What is Prime Number?
Definition : A prime number is a natural number that has only two divisor. Either it is divisible by 1 or itself and it is greater than 1. So we can say it has only one divisor means it can only divided by itself.
Here is the example of prime number in Java. It display all the prime numbers between 1 and the limit entered by user. Get the source code of prime number example here :
import java.io.*;
class Primenumberexample {
public static void main(String[] args) throws Exception{
BufferedReader bf = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter Limit to Print Prime Number :");
int k = Integer.parseInt(bf.readLine());
System.out.println("Prime Numbers Are : ");
for (int i=1; i < k; i++ ){
for (int j=2; j < i; j++){
int a = i%j;
if (a==0){
break;
}
}
if(i == j){
System.out.print(" "+i);
}
}
}
}
Tuesday, July 1, 2008
Monday, June 30, 2008
How to Calculate Area of Rectangle?
class Rectangleexample
{
public static void main(String[] args)
{
int len=5, breadth=7, area=1;
area = len*breadth;
System.out.println("Area if Rectangle :" + area);
}
}
Subscribe to:
Posts (Atom)