1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anarel [89]
3 years ago
15

Debug the code in the starter file so if functions as intended and does not cause any errors. This program is intended to take t

wo 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 by 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(;
intb scan.nextInt();
if(b% a = 0 || a
OD
system.out.println(b + " is not a multiple of " + a);
else
system.out.println(b + is a multiple of " + a);
10
}
}
Computers and Technology
1 answer:
Paladinen [302]3 years ago
7 0

Debugging a code involves finding and fixing the errors in a code.

The errors in the code are as follows:

  • <em>Class name</em>
  • <em>Print statements</em>
  • <em>Variable declarations</em>
  • <em>Input statements</em>
  • <em>If condition</em>

<em><u /></em>

<u />

<u>The class name </u>

The class name of the program is <em>U3_L5_Activity Two</em>

A class name cannot <em>contain space</em>; instead you make use of an <em>underscore.</em>

So, the correct class name is: <em>U3_L5_Activity_Two or U3_L5_ActivityTwo</em>

<u>The print statement</u>

Java differentiates lower and upper case letters.

The print statements in the program begin with a <em>small letter s</em>. This is wrong

So, the correct statements are:

  • <em>System.out.println("Enter two numbers");</em>
  • <em>System.out.println(b + " is a multiple of " + a);}</em>
  • <em>System.out.println(b + " is not a multiple of " + a);</em>

<u />

<u>The declaration and the input statements</u>

Variables a and b were declared wrongly, and the input statements are also wrong.

The correct statements are:

  • <em>int a = scan.nextInt(); </em>
  • <em>int b = scan.nextInt(); </em>

<em />

<u>The condition</u>

The if condition is not properly formatted.

The correct statement is: <em>iif(b%a == 0)</em>

Hence, the correct code is:

<em>import java.util.Scanner; </em>

<em>public class Main{ </em>

<em>public static void main(String[] args) { </em>

<em>    Scanner scan = new Scanner(System.in); </em>

<em>    System.out.println("Enter two numbers"); </em>

<em>    int a = scan.nextInt(); </em>

<em>    int b = scan.nextInt(); </em>

<em>    if(b%a == 0){ </em>

<em>        System.out.println(b + " is a multiple of " + a);} </em>

<em>    else{ </em>

<em>        System.out.println(b + " is not a multiple of " + a); </em>

<em>    } </em>

<em>} </em>

<em>}</em>

<em />

Read more about debugging at:

brainly.com/question/23527739

You might be interested in
The advantages of the dynamo
Dvinal [7]
It produces DC power and it's cheap to make. efficiency is low tho, better to use a alternator
8 0
3 years ago
You are designing software for elderly people. Which two features can you
romanna [79]

give instructions in both text and audio formats

7 0
3 years ago
Suppose you have two arrays of ints, arr1 and arr2, each containing ints that are sorted in ascending order. Write a static meth
telo118 [61]
Since both arrays are already sorted, that means that the first int of one of the arrays will be smaller than all the ints that come after it in the same array. We also know that if the first int of arr1 is smaller than the first int of arr2, then by the same logic, the first int of arr1 is smaller than all the ints in arr2 since arr2 is also sorted.

public static int[] merge(int[] arr1, int[] arr2) {
int i = 0; //current index of arr1
int j = 0; //current index of arr2
int[] result = new int[arr1.length+arr2.length]
while(i < arr1.length && j < arr2.length) {
result[i+j] = Math.min(arr1[i], arr2[j]);
if(arr1[i] < arr2[j]) {
i++;
} else {
j++;
}
}
boolean isArr1 = i+1 < arr1.length;
for(int index = isArr1 ? i : j; index < isArr1 ? arr1.length : arr2.length; index++) {
result[i+j+index] = isArr1 ? arr1[index] : arr2[index]
}
return result;
}


So this implementation is kind of confusing, but it's the first way I thought to do it so I ran with it. There is probably an easier way, but that's the beauty of programming.

A quick explanation:

We first loop through the arrays comparing the first elements of each array, adding whichever is the smallest to the result array. Each time we do so, we increment the index value (i or j) for the array that had the smaller number. Now the next time we are comparing the NEXT element in that array to the PREVIOUS element of the other array. We do this until we reach the end of either arr1 or arr2 so that we don't get an out of bounds exception.

The second step in our method is to tack on the remaining integers to the resulting array. We need to do this because when we reach the end of one array, there will still be at least one more integer in the other array. The boolean isArr1 is telling us whether arr1 is the array with leftovers. If so, we loop through the remaining indices of arr1 and add them to the result. Otherwise, we do the same for arr2. All of this is done using ternary operations to determine which array to use, but if we wanted to we could split the code into two for loops using an if statement.


4 0
4 years ago
Yahoo Messenger is an example of a/an __________ service on the Internet.
barxatty [35]

Answer:

Yahoo Messenger is an example of a service on the Internet.

7 0
3 years ago
Read 2 more answers
ask user to input a string. (assume length of input string is 1) If the string is lower case, print its upper case If the string
Helga [31]

Answer:

import java.util.*;

import java.util.Scanner;

class Main

{

public static void main(String[] args) {

System.out.println("Enter String");

Scanner sc1=new Scanner(System.in);

String s1= sc1.nextLine();

boolean b= isNumerc(s1);

if (b== true)

{

    System.out.println("Its number: Sorry");

}

else

{

boolean a=isStringUpperCas(s1);

if(a == false)

{

    System.out.println(s1.toUpperCase());

}

else

{

    System.out.println(s1.toLowerCase());

}

}

}

private static boolean isStringUpperCas(String st1){

     

     

      char[] arr = st1.toCharArray();

     

      int k =0; boolean flag=true;

      while(k<arr.length)

      {

         

          if( Character.isUpperCase( arr[k] ))

          {

              flag=true;

              k++;

          }

          else

          {

              flag=false;

              k++;

          }

         

      }

      return flag;

}

             

  public static boolean isNumerc(final String st1) {

     

      if (st1 == null || st1.length() == 0) {

          return false;

      }

      for (char ch : st1.toCharArray()) {

          if (!Character.isDigit(ch)) {

              return false;

          }

      }

      return true;

  }

 

}

Explanation:

Please find the program above.

8 0
3 years ago
Other questions:
  • Write a Python function merge_dict that takes two dictionaries(d1, d2) as parameters, and returns a modified dictionary(d1) cons
    5·1 answer
  • Windows XPProfessional and Windows Vista Both have same devicedrivers.<br> True<br> False
    5·1 answer
  • A _____ defines what must take place, not how it will be accomplished.​
    12·1 answer
  • Which of the following technologies allows you to decouple the physical storage hardware from the storage requirements of the ap
    6·1 answer
  • Am I correct? Please help
    7·1 answer
  • Define the term algorithm and describe how programmers use algorithms when designing a program.
    8·1 answer
  • Please explain what is Ribbon?  give examples​
    7·2 answers
  • Write 10 sentences of your own and underline the verb.
    11·1 answer
  • Which three options below describe typographic hierarchy?
    12·1 answer
  • is a programming model that focuses on an application's components and data and methods the components use. Group of answer choi
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!