The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.

// Displays five random numbers between
// (and including) user-specified values
import java.util.Scanner;
public class DebugSix4
{
public static void main(String[] args)
{
int high, low, count = 0;
final int NUM = 5;
Scanner input = new Scanner(System.in);
System.out.print("This application displays " + NUM +
" random numbers" +
"\nbetween the low and high values you enter" +
"\nEnter low value now... ");
low = input.nextInt()
System.out.print("Enter high value... ");
high = inputnextInt();
while(low < high)
{
System.out.println("The number you entered for a high number, " +
high + ", is not more than " + low);
System.out.print("Enter a number higher than " + low + "... ");
high = input.nextInt();


while(count < NUM)
{
double result = Math.random();
int answer = (int) (result * 10 + low);
if(answer <= higher)
{
System.out.print(answer + " ");
++count;
}
}
System.out.println("End of Application");
}
}

Respuesta :

Answer:

Corrected code is highlighted.

  1. // Displays five random numbers between
  2. // (and including) user-specified values
  3. import java.util.Scanner;
  4. public class DebugSix4
  5. {
  6. public static void main(String[] args)
  7. {
  8.     int high, low, count = 0;
  9.     final int NUM = 5;
  10.     Scanner input = new Scanner(System.in);
  11.     System.out.print("This application displays " + NUM +
  12.     " random numbers" +
  13.     "\nbetween the low and high values you enter" +
  14.     "\nEnter low value now... ");
  15.      low = input.nextInt() ;
  16.      System.out.print("Enter high value... ");
  17.      high = input.nextInt();
  18.      while(low > high)
  19.       {
  20.            System.out.println("The number you entered for a high number, " +
  21.           high + ", is not more than " + low);
  22.             System.out.print("Enter a number higher than " + low + "... ");
  23.            high = input.nextInt();
  24.       while(count < NUM)
  25.       {
  26.          double result = Math.random();
  27.          int answer = (int) (result * 10 + low);
  28.          if(answer <= high)
  29.          {
  30.              System.out.print(answer + " ");
  31.             ++count;
  32.           }
  33.         }
  34.       System.out.println("End of Application");
  35.    }
  36. }

Explanation:

Line 15 misses a semicolon at the end. It is syntax error

Line 17 misses a . between input and nextInt(). Dot syntax is required to invoke method.

Line 18 shows a logical error. it should be low > high so that the program can detect the error where the input value for high variable is lower than the variable low.

Line 30 shows a variable higher which doesn't exist. It should be changed to high.