continue break

Write a program to input a number until user presses between 1 and 10 using continue and break.

 

import java.util.Scanner; class P12ContinueBreak { public static void main() { int x; while(true) { System.out.println("Enter an integer between 1 and 10"); Scanner in = new Scanner(System.in); x= in.nextInt(); if(x<1 || x>10) continue; //skip the rest part of loop only for this iteration System.out.println(+x +" is between 1 and 10"); break; // exit loop regardless of condition } } }




For any desired program, please comment below. We will try our best to make that program available.


Comments

Popular Posts