Sunday, January 20, 2008

Program To Print All the NON Fibonacci Numbers


Write a function print() that accepts two numbers and print all the numbers between them,except those two numbers
Using this function, write a program to print all the non-fibonacci numbers from 1-100

Quadratic Equation

Wap to input the values of three coefficients of a quadratic equation
AX(Square)+BX+C=0
Find the roots of the Equation and display them , stating wether they are real,imaginary or equal
Also print the value of X

import java.io.*;
class Quadratic
{
public int a,b,c;
public void Quadratic()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter the value A");
int a = Integer.parseInt(br.readLine());
System.out.println(" Enter the value B ");
int b = Integer.parseInt(br.readLine());
System.out.println(" Enter the value C ");
int c = Integer.parseInt(br.readLine());
}
public void Values()
{
double x1,x2;
int z = (b*b)-(4*a*c);
if(z>0)
{
System.out.println(" Real Roots ");
x1=(-b+Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println( " Root 1 " + x1);
x2=(-b-Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println( " Root 2 " + x2);
}
else if(z==0)
{
System.out.println(" Equal Roots ");
x1= (b)/(2*a);
System.out.println(" Root = " +x1);
}
else if(z<0)
{
System.out.println(" Imaginary Roots ");
}
}
public static void main(String args[])throws IOException
{
Quadratic Q = new Quadratic();
Q.Quadratic();
Q.Values();
}
}

Saturday, January 19, 2008

String based Program

Write a Program to accept a String and print it in following manner
Input - Harsh Kumar Agrawal ( Just an Example)
Output - H.K.Agrawal






Frequency Of Vowels In the String

Q Write a Program to Find the Number of times vowels Occure in a given String

Method 1 - Of anshul
import java.io.*;
class vowels{ public static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String str;
int i,c=0,j;
System.out.println("Enter a string");
str=in.readLine();
str=str.toLowerCase();
for(i=0;i<=str.length()-1;i++)
{
j=str.charAt(i);
if(j==' ')
{
if((j+1)=='a'(j+1)=='e'(j+1)=='i'(j+1)=='o'(j+1)=='u')
c++;
}
}
if(str.charAt(0)=='a'str.charAt(0)=='e'str.charAt(0)=='i'str.charAt(0)=='o'str.charAt(0)=='u')
c++;
System.out.println("\n no. of words starting with vowels::::"+c);
}
}

Method 2 (By Harsh)(me :))
import java.io.*;
class Proverbial
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter a String ");
String s=br.readLine();
char ch;
s=s.toLowerCase();
int c=0,l=s.length();
for(int i=0;i
{
ch=s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
c++;
}
System.out.println(" Frequency of Vowels is "+ c);
}
}





Wednesday, January 16, 2008

Perfect Number

A perfect Integer is a number which is equal to the sum of all its factors
eg - 28 is a perfect integer as it is the sum of all its factor -
1 + 2 + 4 + 7 + 14 = 28
Wap to display perfeect integers form 1 to 1000
Evergreen Publications Model Paper1 Q9


[2D Array] Sum of diagonals

Wap To input numbers into a array of 3 rows And 3 coloumns . find the sum of the numbers in the diagonal elements . no element should be repeated twice
Evergreen Publication Model paper 1 Q8

import java.io.*;
class SumDiagonal
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][3];
int Sum=0;
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Matrix ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i==j)
Sum = Sum + a[i][j];
if(i+j==2&&i!=j)
Sum = Sum + a[i][j];
}
}
System.out.println("Sum of Diagonal = "+Sum);
}
}

Request a Program Here

Here u can Ask a question for a Program and i'll make that program and publish it here

HCF and LCM of 2 numbers

import java.io.*;
class lowhigh
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a,b,c,i,j,t,k,p,lcm,hcf=1;
System.out.println(" Enter any 3 number ");
a = Integer.parseInt(br.readLine());
b = Integer.parseInt(br.readLine());
c = Integer.parseInt(br.readLine());
p = a*b*c;
for(i=1;i<=p;i++)
{
j = a%i;
t = b%i;
k = c%i;
if(j==0&&t==0&&k==0)
{
hcf = i;
}
}
lcm = p/hcf;
System.out.println(" the lcm is " + lcm);
System.out.println(" the hcf is " + hcf);
}
}

Find the Longest Word in the String

import java.io.*;
class LongestWord
{
public static void main(String args[])throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String");
String s=in.readLine();
int l=s.length();
String wo="",w="";
s=s+" ";
int max=0,x;
for(int i=0;i {
char ch=s.charAt(i);
if(ch!=' ')
{
wo = wo+ch;
}
else
{
x=wo.length();
if(x>max)
{
max=x;
w=wo;
}
wo="";
}
}
System.out.println("Longes Word is " + wo);
}
}

Count the number of spaces in a String

This Program count the number of spaces in a String

import java.io.*;
class spaces
{
public static void main(String args[])throws IOException
{
int c=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter a String ");
String s = br.readLine();
int l= s.length();
for(int i=0;i{
char ch=s.charAt(i);
if(ch==' ')
c=c+1;
}
System.out.println("Number of spaces " + c);
}
}

Palindrom String

Check a String is palindrom or not

import java.io.*;
class palindrom
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter a String ");
String s = br.readLine();
int l=s.length();
String x = "";
int ch;
ch=0;
for(int i=l-1;i>=0;i--)
{
x=x+s.charAt(i);
}
if(x.compareTo(s)==0)
System.out.println(" its A palindrom");
else
System.out.println(" its not a palindrom ");
}
}

Pattern Alphabetic Diamond

A

A B

A B C

A B C D

A B C

A B

A

This is the output

class ABCD
{
public static void main(String a[])
{
char c;
for(int i=1;i<=7;i++)
{
int x = 65;
if(i<5)
{
for(int j = 4 ; j>=i;j--)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
c=(char)x;
System.out.print(c + " " );
x=x+1;
}
}
else
{
for(int j=4;j<=i;j++)
{
System.out.print(" ");
}
for(int j=7;j>=i;j--)
{
c=(char)x;
System.out.print(c + " ");
x = x + 1;
}
}
System.out.println();
}
}
}

Pattern Inverted Triangle

+++++

++++

+++

++

+

this is the output of this program

class LeftTriangle
{
public static void main()
{
for(int i=0;i<5;i++)
{
for(int j=5;j>i;j--)
{
System.out.print("+");
}
System.out.println();
}
}
}

Pattern RightTriangle

1

12

123

1234

this will be printed By this program

class RightTriangle
{
public static void main()
{
for(int i=0;i<5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}

[2D array] TransPose of array

transpose

2 3 2 4
4 5 becomes 3 5



import java.io.*;
class Transpose
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[2][3];
int b[][]=new int[3][2];
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Matrix ");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
System.out.println(" Trasposed ");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
b[j][i]=a[i][j];
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println();
}
}
}

[2D array] Sum of Right Diagonal

Wap to find the Sum of Right Diagonal in a 2D Array

import java.io.*;
class SumDiagonalR
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][3];
int Sum=0;
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Matrix ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i+j==2&&i!=j)
Sum = Sum + a[i][j];
}
}
System.out.println("Sum of Right Diagonal = "+Sum);
}
}

[2D array] Sum of left Diagonal

Wap a program to find the Sum of the Left diagonal of a 2D array

import java.io.*;
class SumDiagonal
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][3];
int Sum=0;
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Matrix ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i==j)
Sum = Sum + a[i][j];
}
}
System.out.println("Sum of left Diagonal = "+Sum);
}
}

Find the Mean of the Array

import java.io.*;
class Mean
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
int a=0,i=0,j=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 Values");
int sum=0,mean=0;
for(i=0;i<10;i++)
{
x[i]=Integer.parseInt(br.readLine());
sum=sum+x[i];
}
mean = sum/10;
System.out.println(" Mean = "+mean);
}
}

Search[Array]

WAP to find a particular element is a array and Display its position in the array

import java.io.*;
class PositionSearch
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
int a=0,i=0,j=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 Values");
for(i=0;i<10;i++)
{
x[i]=Integer.parseInt(br.readLine());
}
System.out.println(" Enter the Value u want to search ");
int n=Integer.parseInt(br.readLine());
for(i=0;i<10;i++)
{
if(x[i]==n)
System.out.println(" the desired element is present at position " + i );
}
}
}

WAP to find the Max and Min element in a Array

import java.io.*;
class MaxMin
{
public static void main(String args[])throws IOException
{
int x[]=new int[5];
int a=0,i=0,j=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 5 Values");
for(i=0;i<5;i++)
{
x[i]=Integer.parseInt(br.readLine());
}
int max,min;
max=x[0];
min=x[0];
for(i=0;i<5;i++)
{
if(x[i]>max)
max=x[i];
if(x[i]min=x[i];
}
System.out.println(" Max = " + max);
System.out.println(" Min = " + min);
}
}

Sort an array using Bubble sort technique

import java.io.*;
class BubbleSort
{
public static void main(String args[])throws IOException
{
int x[]=new int[5];
int a=0,i=0,j=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 5 Values");
for(i=0;i<5;i++)
{
x[i]=Integer.parseInt(br.readLine());
}
for(i=0;i{
for(j=0;j{
if(x[j]>x[j+1])
{
a=x[j];
x[j]=x[j+1];
x[j+1]=a;
}
}
}
System.out.println("Result");
for(i=0;i<5;i++)
{
System.out.println(x[i]+"\t");
}
}
}

Sort an array using selection sort technique

import java.io.*;
class SelectionSort
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 Integer values ");
for(int i=0;i<10;i++)
{
x[i] = Integer.parseInt(br.readLine());
}
int h,p=0;
for(int i=0;i{
h=x[i];
for(int j=i;j{
if(x[j]>h)
{
h=x[j];
p=j;
}
}
x[p]=x[i];
x[i]=h;
}
System.out.println(" After Sorting");
for(int i =0;i<=x.length-1;i++)
{
System.out.println(x[i]);
}
}
}

[2D array]Sum of Even and Odd

WAP a program to find the product of all the even elements and all the odd elements present in the array

//Wap to Store 12 elements in a array of size 3X4 and find the sum of all the elements
//and product of even elements and odd elements.

import java.io.*;
class EvenOdd
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][4];
int s=0,even=1,odd=1;
System.out.println(" Enter 12 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
s=s+a[i][j];
if(a[i][j]%2==0)
even=even*a[i][j];
else
odd=odd*a[i][j];
}
}
System.out.println(" Sum = " +s);
System.out.println(" Product of Even = " + even );
System.out.println(" Product of odd = " + odd);
}
}

Substraction Of 2D matrix

import java.io.*;
class MatrixSubs
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[2][3];
int b[][]=new int[2][3];
int c[][]=new int[2][3];
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Enter 6 elements for array 2 :");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
b[i][j]=Integer.parseInt(br.readLine());
c[i][j]=a[i][j]-b[i][j];
}
}

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}

Addition Of 2D matrix

import java.io.*;
class Matrizadd
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[2][3];
int b[][]=new int[2][3];
int c[][]=new int[2][3];
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Enter 6 elements for array 2 :");
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
b[i][j]=Integer.parseInt(br.readLine());
c[i][j]=a[i][j]+b[i][j];
}
}

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}

Smallest and Largest Digit present in a Number

Topic says the question


import java.io.*;
class LSdigits
{
public static void main(String args[])throws IOException
{
int i,x,num,n,l,h;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter any Number ");
num=Integer.parseInt(br.readLine());
n=num;
h=0;l=9;
do
{
x=n%10;
if(x>h)
h=x;
if(xl=x;
n=n/10;
}while(n>0);
System.out.println("Largest number = "+h+" Lowest number = " + l);
}
}

Frequency Of each Character of a String

import java.io.*;
class Frequency
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s;
char ch ;
System.out.println("Enter a String ");
s=br.readLine();
for(int i=0;i{
int c=0;
ch=s.charAt(i);
for(int j=0;j{
if(s.charAt(j)==ch)
c++;
}
System.out.println(ch + " has " + c + " frequency ");
}
}
}

Fibonacci Series

import java.io.*;
class fibonacci
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n,a=0,b=1,i,c;
System.out.println(" Enter any number ");
n = Integer.parseInt(br.readLine());
System.out.println(a+"\t"+b);
for(i=1;i<=n;i++)
{
c=a+b;
System.out.println("\t" +c);
a=b;
b=c;
}
}
}

Find the number with Highest number of Factors in a Array

Simple Prog

import java.io.*;
class NoFactor
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
int max=0,a=0,c=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 integers");
for(int i=0;i<10;i++)
{
c=0;
x[i]=Integer.parseInt(br.readLine());
for(int j=1;j<=x[i];j++)
{
if(x[i]%j==0)
c++;
}
if(c>max)
{
a=x[i];
}
}
System.out.println("The number with highest number of factor = " + a +"with"+c+"factors");
}
}

Rupees To Dollar

import java.io.*;
class Dollar
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a,r,d;
System.out.println(" the amount in rupees ");
a = Integer.parseInt(br.readLine());
System.out.println(" the rate of conversion into dollars ");
r = Integer.parseInt(br.readLine());
d = a/r;
System.out.println("the conversion into dollar " +d);
}
}

PrimePalindrom

This number checks wether a number is prime as well as palindrom

import java.io.*;
class Primepalindrom
{
public void accept()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number");
int n=Integer.parseInt(br.readLine());
Primepalindrom p = new Primepalindrom();
p.checkprime(n);
}
void checkprime(int n)
{
int i = 1;
double s=0;
int fact;
for(i=1;i<=n;i++)
{
if(n%i==0)
s=s+1;
}
if(s==2)
{
Primepalindrom p = new Primepalindrom();
p.checkpalindrom(n);
}
else
System.out.println("the number is not prime");
}
void checkpalindrom(int n)
{
int d,x,dup=0;
d=n;
do
{
x=d%10;
dup= dup*10+x;
d=d/10;
}
while(d>0);
if(dup==n)
System.out.println("The number is primepalindrom");
else
System.out.println("the number is not primepalindrom");
}
public static void main(String args[])throws IOException
{
Primepalindrom p = new Primepalindrom();
p.accept();
}
}

Covert Rupees To there Corresponding Notes

Easy One

import java.io.*;
class RupeesToNotes
{
public static void main(String args[])throws IOException
{
int amt,p20,p10,p5,p2,p1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" enter the amount ");
amt = Integer.parseInt(br.readLine());
p20 = amt/20;
amt = amt%20;
System.out.println("20 X " + p20);
p10 = amt/10;
amt = amt%10;
System.out.println("10 X " + p10);
p5 = amt/5;
amt = amt%5;
System.out.println("5 X " + p5);
p2 = amt/2;
amt = amt%2;
System.out.println("2 X " + p2);
p1 = amt;
System.out.println("1 X " + p1);
}
}

PythaGorian Triplets

Like 5,4,3 are Pythagorian Triplets this programs Finds all

import java.io.*;
class triplet

{
public static void main()
{
int i,j,k;
for(i=1;i<=10;i++)
{
for(j=i+1;j<10;j++)
{
for(k=j+1;k<10;k++)
{
if((i*i)+(j*j)==(k*k))
{
System.out.println(i+" "+j+"and"+k+"are pyth. triplets");
}
}
}
}
}
}

Find Date

Short program Must know

import java.util.*;
class datefind
{
public void main()
{
Date dt = new Date();
System.out.println(" THE date is = " + dt);
}
}

[menudriven]-Area Of all the Shapes

import java.io.*;
class Ar
{
double a;
public void area(int x)
{
a = (3.14)*x*x;
System.out.println(" Area = " + a);
}
public void area()throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int s;
System.out.println(" Enter side ");
s = Integer.parseInt(in.readLine());
a = s*s;
System.out.println(" area " + a);
}
public void area(float l,float b)
{
a = l*b;
System.out.println(" area = " + a);
}
public double area (int h,int p)
{
a = (0.5)*h*p;
return a;
}
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
System.out.println(" 1 : circle ");
System.out.println(" 2 : square ");
System.out.println(" 3 : rectangle ");
System.out.println(" 4 : triangle ");
System.out.println(" Enter your choice ");
int c;
Ar a1 = new Ar();
c = Integer.parseInt(in.readLine());
if(c==1)
{
int r;
System.out.println(" enter radius ");
r = Integer.parseInt(in.readLine());
a1.area(r);
}
else if(c == 2)
{
a1.area();
}
else if(c == 3)
{
float p,q;
System.out.println("enter length and breadth ");
p=Float.parseFloat(in.readLine());
q=Float.parseFloat(in.readLine());
a1.area(p,q);
}
else if(c == 4)
{
int y,z;
double d;
System.out.println(" enter base and hieght ");
y = Integer.parseInt(in.readLine());
z = Integer.parseInt(in.readLine());
d = a1.area(y,z);
System.out.println(d);
}
else
System.out.println(" Invalid ");
}
}


Its made using fuctions

HCF of a Number

Method Used :
The bigger of the two number is divided by the smaller one and remainder obtained. If the remainder is not 0 then the last divisor is divided by the remainder and another remainder is obtained . this goes on till the remainder is 0. when the remainder becomes 0,the number which is Devisor becomes HCF
Write a program To find the HCF of 2 number using above method

Evergreen Publications Model Paper unsolver Q5;

import java.io.*;
class HCF
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter any 2 numbers ");
int x = Integer.parseInt(br.readLine());
int y = Integer.parseInt(br.readLine());
int rem=1,re=1,h=1,s=1;
if(x>y)
{
h=x;
s=y;
}
else if(y>x)
{
h=y;
s=x;
}
do
{
rem =h%s;
if(rem>0)
{
re = s%rem;
s=rem;
rem = re;
}
else
{
System.out.println(s);
break;
}

}
while(rem>=0);

}
}

Prime Number

Here is a Program to find a number is prime or not

import java.io.*;
class prime
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter any no,");
int a = Integer.parseInt(br.readLine());
int fac=0;
for(int i =2;i{
if(a%i==0)
fac=1;
break;
}
if(fac==0)
System.out.println("Prime Number");
else
System.out.println("Not Prime Number");
}
}

Armstrong Number

Here is a Program to find out if a number is armstrong or not

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

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int d,n,dup,sum=0;
System.out.println("Enter a NO.:");
n = Integer.parseInt(br.readLine());
for(dup=n;n>0;n/=10)
{
d=n%10;
sum = sum + d*d*d;
}
if (sum==dup)
System.out.println(dup+ " is an armstrong no.");
else
System.out.println(dup+ " is not an armstrong no.");
}
}