Program of factorial number
class operation
{
static int fact(int number)
{
int f=1;
for(int i=1;i<=number;i++)
{
f=f*i;
}
return f;
}
public static void main(String args[])
{
int result=fact(5);
System.out.println("Factorial of 5="+result);
}
}
Program of fibonacci series
class fabnoci
{
public static void main(String[] args)
{
int n=10,i,f0=1,f1=1,f2=0;
for(i=1;i<=n;i++)
{
f2=f0+f1;
f0=f1;
f1=f2;
f2=f0;
System.out.println(f2);
}
}
}
Program of Armstrong number
class armstrong
{
public static void main(String...args)
{
int n=153,c=0,a,d;
d=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(d==c)
System.out.println("armstrong number");
else
System.out.println("it is not an armstrong number");
}
}
Program of checking palindrome number
class palindrome
{
public static void main( String...args)
{
int a=242;
int n=a,b=a,rev=0;
while(n>0)
{
a=n%10;
rev=rev*10+a;
n=n/10;
}
if(rev==b)
System.out.println("it is Palindrome");
else
System.out.println("it is not palinedrome");
}
}
Program of swapping two numbers without using third variable
class swaptwonumbers
{
public static void main(String args[])
{
int a=40,b=5;
a=a*b;
b=a/b;
a=a/b;
System.out.println("a= "+a);
System.out.println("b= "+b);
}
}
No comments:
Post a Comment