Question: Find the errors in the following code: 1. // This code contains ERRORS! // It adds two numbers entered by the user. int num1, num2;

Find the errors in the following code:

1. // This code contains ERRORS! // It adds two numbers entered by the user. int num1, num2; String input; char again;

Scanner keyboard = new Scanner(System.in); while (again == 'y' || again == 'Y')

System.out.print("Enter a number: "); num1 = keyboard.nextInt(); System.out.print("Enter another number: ";

num2 = keyboard.nextInt(); System.out.println("Their sum is "+ (num1 + num2)); System.out.println("Do you want to do this again? "); keyboard.nextLine(); // Consume remaining newline input = keyboard.nextLine(); again = input.charAt(0);

2. // This code contains ERRORS!

int count = 1, total; while (count <= 100)

total += count; System.out.print("The sum of the numbers 1 - 100 is "); System.out.println(total);

3. // This code contains ERRORS! int choice, num1, num2; Scanner keyboard = new Scanner(System.in); do {

System.out.print("Enter a number: "); num1 = keyboard.nextInt(); System.out.print("Enter another number: "); num2 = keyboard.nextInt(); System.out.println("Their sum is " + (num1 + num2)); S

ystem.out.println("Do you want to do this again? ");

System.out.print("1 = yes, 0 = no ");

choice = keyboard.nextInt();

} while (choice = 1)

4. // This code contains ERRORS! // Print the numbers 1 through 10. for (int count = 1, count <= 10, count++;) {

System.out.println(count);

count++; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!