- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltprime.java
More file actions
Latest commit
24 lines (22 loc) · 488 Bytes
/
Copy pathAltprime.java
File metadata and controls
24 lines (22 loc) · 488 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
publicclassAltprime
{ publicstaticvoidmain(String[] args)
{ intn =100,flag,num,i,temp=2;
System.out.println("Alternate prime numbers up to " + n+" are: \n");
for(num = 2; num <= n-1; num++)
{ flag=0;
for(i = 2; i<= num / 2; i++)
{ if(num%i==0)
{ flag=1;
break;
}
else
flag=0;
}
if(flag==0)
{ if(temp%2==0)
System.out.print(num+"\t");
temp++;
}
}
}
}