What We Are Learn On This Post
Prime Number Java Program: A prime number is a natural number, which is greater than 1 and that has no positive divisions other than 1 and itself.
Example: 1,2,3,5,7,11,13… etc
package com.java.Softwaretestingblog; public class Primeno { public static void main(String[] args) { // TODO Auto-generated method stub int i,k,j; for(i=1;i<100;i++) { k= 0; for(j=2;j<i;j++) { if(i%j== 0) { k=1; break; } } if(k==0) { System.out.println(i); } } } }
Execution: If the above image is not visible clearly then you can use this link
Check Also: ReferEnce Variable Java Example
Output:
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Leave a Reply