Tuesday, August 31, 2010

Java : List Prime Numbers between 1 to Given Number

This program find the even numbers between 1 to the number enter by user :

import java.io.*;
class AllEvenNum{
public static void main(String[] args) {

try{

BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number : ");
int num = Integer.parseInt(< /span>br1.readLine());
System.out.println("Even Numbers are:");
for (int i=1;i <=num ; i++){
if(i%2==0
){
System.out.print(i+",");
}
}
}
catch(Exception e){}
}
}



List prime numbers

No comments:

Post a Comment