Q:

write java program prompts user to enter unlimited numbers, and when user enters the value -1 then program ends and print bye

0

write java program prompts user to enter unlimited numbers, and when user enters the value -1 then program ends and print bye

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
int value;
	    while(true)//inifinite loop
	    {
	     System.out.println("enter a number: (press -1 to exit)");
	     Scanner input=new Scanner(System.in);
	     value=input.nextInt();
	     if(value==-1)
	     break;
	     else System.out.println("you entered "+value);
	    }
	    System.out.println("bye");
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now