Question

In: Computer Science

Debug the code in the starter file so it functions as intended and does not cause...

Debug the code in the starter file so it functions as intended and does not cause any errors. This program is intended to take two integer inputs and determine whether the second is a multiple of the first or not. The number b is a multiple of the number a if b can be divided by a with no remainder. Remember though that no number can be divided by 0 - so no numbers should be considered a multiple of 0 for the purpose of this exercise.

/* Lesson 5 Coding Activity Question 2 */

import java.util.Scanner;

public class U3_L5_Activity_Two{

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

System.out.println("Enter two numbers");

int a = scan.nextInt();

int b = scan.nextInt();

if((b % a =! 0 | a == 0)

System.out.println(b + " is not a multiple of " + a);

else

System.out.println(b + " is a multiple of " + a);

}

}

Solutions

Expert Solution

import java.util.Scanner;

// Defines class U3_L5_Activity_Two
public class U3_L5_Activity_Two
{
   // main method definition
   public static void main(String[] args)
   {
       // Scanner class object created
       Scanner scan = new Scanner(System.in);

       System.out.println("Enter two numbers");
       // Accepts first number
       int a = scan.nextInt();
       // Accepts second number
       int b = scan.nextInt();
      
       // Checks if b is not divisible by a or a is 0
       // then not multiple
       if((b % a != 0) || a == 0)
           System.out.println(b + " is not a multiple of " + a);

       // Otherwise divisible and it is multiple
       else
           System.out.println(b + " is a multiple of " + a);
       // Close the scanner class
       scan.close();
   }// End of main method
}// End of class

Sample Output 1:

Enter two numbers
2
12
12 is a multiple of 2

Sample Output 2:

Enter two numbers
9
25
25 is not a multiple of 9


Related Solutions

I am given this starter code and I am suppose to debug it and all of...
I am given this starter code and I am suppose to debug it and all of that and it will not work after I change ">" to "<=" and then i'm not sure after that what else I have to do. Could someone help me solve this? // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 {    public static void main(String args[])    {      ...
Rewrite this code of a game of Moropinzee so that it works as intended without the...
Rewrite this code of a game of Moropinzee so that it works as intended without the "break;" in the last few lines of the code. Code: import java.util.*; public class Moropinzee { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("Player 1 enter a number 1-5 for Monkey, Robot, Pirate, Ninja, or Zombie:"); int p1 = sc.nextInt(); while(p1<1 || p1>5) { System.out.println("Invalid choice, Player 1. Enter a number 1-5:"); p1 = sc.nextInt(); } System.out.println("Player 2...
Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file...
Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file for the following problem: Input: a number, n, using prompt, which is the number of the factorial numbers to be displayed. Output: a bordered table of numbers with proper caption and headings in which the first column displays the numbers from 1 to n and the second column displays the first n factorial numbers. For example, if a user enters 10 to be the...
Into to PythonInstructions: • In this lab you are to debug the code found at...
Into to PythonInstructions: • In this lab you are to debug the code found at the end of these instructions: Find and correct all problems found in the code. Create comments in the code explaining what you found and how you corrected it • The purpose of this program is to calculate car insurance rates using the following rules: The base rate of insurance is $50 a month, Males pay a 25% premium over the base rate, Drivers in Michigan...
This is c++ code. Create a file sort.cpp. to mix functions with the selection sort algorithm:...
This is c++ code. Create a file sort.cpp. to mix functions with the selection sort algorithm: ·Write a function int least(vector<string> strs, int start)to return the index of the smallest value in the vector. You are to assume there is at least one value in the vector. ·Write a function void selsort(vector<string> & strs) to use selection sort to sort the vector of strings. It is a worthwhile experiment to try leaving out the & and seeing that the vector...
Using steps.py in this repository for a starter file, write a Python program to calculate average...
Using steps.py in this repository for a starter file, write a Python program to calculate average number of steps per month for a year. The input file (which you will read from the command line, see the sample program on how to read command line arguments in this repository) contains the number of steps (integer) a person took each day for 1 year, starting January 1. Each line of input contains a single number. Assume this is NOT a leap...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire assignment. There are no more directions to it. Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make...
Python 3 Fix the code so the program reads the file and see if the bar...
Python 3 Fix the code so the program reads the file and see if the bar code was already inputted 3 times if so, it ishows a warning indicating that the item was already tested 3 times Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window,...
Debug the pet.h file and pet.cpp file (I would like to check my work) #ifnotdef PET_H...
Debug the pet.h file and pet.cpp file (I would like to check my work) #ifnotdef PET_H #then_define PET_H #include <string> using name space std namespace fhsuzeng { Class Pet { public Pet(); void setName(string name); string getName() const; void setAge(double age); int getAge() const; virtual void talk(); private: string _name; int _age; }; class Dog::public Pet { public: Dog(); void setBreed(string breed); string getBreed() const; private: string _breed; } class Cat:Pet { Public: Cat(); void setColor(string color); string getColor() const;...
Build a module (file with pre-defined functions) that allows the following code to work properly. The...
Build a module (file with pre-defined functions) that allows the following code to work properly. The code below should be able to run without any additions or modifications. You may copy and paste it into a file called file_tools_assignment.py and place it in the same directory as the file you will create. The filename of the file you will create should be file_tools.py. The module should contain 2 custom defined functions; get_file_string() and get_file_list(). Download the data.txt file and place...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT