Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. // int count = 1, total; while (count <= 100)

This code contains ERRORS!

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

// 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)); System.out.println("Do you want to do this again? "); System.out.print("1 = yes, 0 = no ");

choice = keyboard.nextInt(); } while (choice = 1)

// 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions