examples of break and continue in java
All Contributions
example of break statement:
write java program prompts user to enter unlimited numbers, and when user enters the value -1 then program ends and print bye
-------------
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");
}
}
total contributions (2)
using continue statement, write java program prints even numbers between 0 to 100
---------------
answer: