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 newlineinput = keyboard.nextLine();again = input.charAt(0);

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

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);

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT