Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Even though the steps is written in Chegg answers i get the error message: FixDe

ID: 3759490 • Letter: E

Question

Even though the steps is written in Chegg answers i get the error message:

FixDebugSix4.java:27: error: variable count might not have been initialized
while(count < NUM)
1 error

Here is my coding for the file FixDebugSix4.java and i don't know where i'm going wrong with it.

/* Rakesh Acharya
Today's Date:November 3, 2015
Purpose of the program:Displays 5 random numbers between (and including) user-specified values*/
import java.util.Scanner;
public class FixDebugSix4
{
public static void main(String[] args)
{
int high, low, count;
final int NUM = 5;
Scanner input = new Scanner(System.in);
// Prompt user to enter high and low values
System.out.print("This application displays " + NUM +
" random numbers" +
" between the low and high values you enter" +
" Enter low value now... ");
low = input.nextInt();
System.out.print("Enter high value... ");
high = input.nextInt();
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();
// random() returns value between 0 and 1
int answer = (int) (result * 10 + low);
// multiply by 10 and add low -- random is at least the value of low
// only use answer if it is low enough
if(answer <= high)
{
System.out.print(answer + " ");
++count;
}
}

while(count > NUM)
{
double result = Math.random();
// random() returns value between 0 and 1
int answer = (int) (result * 10 + low);
// multiply by 10 and add low -- random is at least the value of low
// only use answer if it is low enough
if(answer <= high)
{
System.out.print(answer + " ");
++count;
}
}

System.out.println();
}
}

Explanation / Answer

Please change it to while(count <= NUM)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote