Posts

Showing posts from July, 2012

java program to check whether the given number is prime or not

import java.util.*; public class IsPrime {     public static void main(String[] args)     {         Scanner sc=new Scanner(System.in);         boolean flag=true;         int n=sc.nextInt();         if(n>=2)         {             for(int i=2;i<n;i++)             {                 if(n%i==0)                   flag=false;             }             if(flag)               System.out.println("is prime");             ...

java program to print 1 to n prime numbers

import java.util.*; public class PrimeNumber {     public static void main(String[] args)     {         Scanner sc=new Scanner(System.in);         int n;         boolean flag=true;         n=sc.nextInt();         for(int i=2;i<=n;i++)         {             for(int j=2;j<i;j++)             {                 if(i%j==0)                    flag=false;             }             if(flag)                System.out.print(i+...