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

Hello I need help trying to get another opinion on this question. This code snip

ID: 674904 • Letter: H

Question

Hello

I need help trying to get another opinion on this question.

This code snippet uses a “while” loop. The intent of the program is to ask the user to enter 10 numbers and only 10 numbers. What is wrong with the code and how would you fix it? How would you test your fix to verify that you fixed the problem(s)?

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
int numbersEntered = 0;
int number;
while (numbersEntered < 10) {
System.out.println("Please enter a number");
number = input.nextInt();
System.out.print("You have entered a total of " + numbersEntered + " ");

}

}

Explanation / Answer

import java.io.*;
import java.util.Scanner;
class ReadAndPrintTenNumbers
{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
int numbersEntered = 0;
int number;
while (numbersEntered < 10) {
numbersEntered++; //This will maintain the counter for numbers entered.
System.out.print("Please enter a number "+numbersEntered+": "); //This will prompt you to enter ith number where i lies between 1 and 10.
number = input.nextInt();
}
System.out.print("You have entered a total of " + numbersEntered + " "); //This will ensure the total numbers (10) entered.

}

}

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