Monday, February 18, 2008


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(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){}
}
}


Monday, February 11, 2008


Table of a Given Number : Java Example

This example explain how to print table of a given number. This is useful example of a java program for the beginners using while loop. We can also use for loop to print table :

Tableexample{
public static void main(String[] args) {
int a=5, b=1;
System.out.println("table of "+a+"= ");
while(b<=10){
int c = a*b;
System.out.println(c);
b = b+1;
}
}
}