0

I am now trying out different types of Java loops for my 5-year salary comparison program. So far, I seem to be having problems with trying out a do-while loop. I use NetBeans to build my programs and when I write the do-while loop in there, it produces several errors that I don't know how to resolve. Maybe my wording sounds incorrect, but let's check it out below to see what needs to be rewritten:

do {
System.out.println("Enter the salary individual 1 got in year 1: ");
    firstIndividualSalary[0] = scan.nextInt();

System.out.println("Enter the salary individual 2 got in year 1: ");
    secondIndividualSalary[0] = scan.nextInt();

if (firstIndividualSalary[0] == secondIndividualSalary[0]) {
        System.out.println("Error. Try again.");
        areAllDifferent = false;
        input.next();
    }

else {
  areAllDifferent = true;
}

while (!(areAllDifferent));

If a do-while loop isn't the right choice for making a user re-enter an answer until their input is correct, then please let me know if either while loops or for loops will make more sense in building a completely error-free program. I personally don't feel like a do-while loop might work at all. I just need to figure out how to make a user re-enter a couple of answers so they don't end up matching each other. And I need to figure out the same issue for calculating the total amounts of 2 individuals' 5-year salaries. I would appreciate it if you took a look at this and answered with some revision suggestions. Thanks.

GGomes4
  • 1
  • 3

0 Answers0