♠ Posted by Unknown in Core Java,IGNOU MCA Practicals at 05:11
IGNOU - MCSL025 - SECTION04 - [S01_E03]
/*Author: Viral Vyas* Write a program in java to explain the use of break and continue statements.
*/
package mcsl025;
import java.io.*;
import java.lang.*;
public class S01_E03 {
public static void main(String[] args){
boolean flag;
for(int x=1; x<=50; x++){
flag = true;
for(int y=2; y<x; y++){
if(x%y == 0) flag=false;
}
if(flag){
//Prime No: 23 not printed due to continue statement
if(x == 23) continue;
//Prime No: 41 to onwards not printed due to break statement
if(x == 41) break;
System.out.println("Prime No : " + x);
}
}
}
}
Output:
Prime No : 1
Prime No : 2
Prime No : 3
Prime No : 5
Prime No : 7
Prime No : 11
Prime No : 13
Prime No : 17
Prime No : 19
Prime No : 29
Prime No : 31
Prime No : 37
0 comments:
Post a Comment