Experiment No 1
/*factorial*/
import [Link];
class Factorial
{
public static void main(String args[])
{
int n, c, fact = 1;
[Link]("Enter an integer to calculate it's factorial");
Scanner sc= new Scanner([Link]);
n = [Link]();
if (n < 0)
[Link]("Number should be non-negative.");
else
{
for (c = 1; c <= n; c++)
fact = fact*c;
[Link]("Factorial of "+n+" is = "+fact);
}
}
}
/*Output
Enter an integer to calculate it's factorial
5
Factorial of 5 is = 120
Enter an integer to calculate it's factorial
-1
Number should be non-negative.
*/
Experiment No 1
/*fibbonacci series*/
import [Link];
class fib
{
public static void main(String rg[ ])
{
int a,b=1,c=0,n,i=1;
Scanner sc= new Scanner([Link]);
[Link]("How many number want in fibonacci series?");
n=[Link]();
[Link]("Fibonacci serie of first %d number\n",n);
while(i<=n)
{
[Link](" "+c);
a=b;
b=c;
c=a+b;
i++;
}
}
}
OUTPUT
How many number want in fibonacci series?
10
Fibonacci serie of first 10 number
0 1 1 2 3 5 8 13 21 34
Experiment No 1
/*Prime Number*/
import [Link];
class prime
{
public static void main (String args[])
{
int n,i,c=0;
[Link]("Enter the number");
Scanner sc=new Scanner([Link]);
n=[Link]();
for(i=2;i<n;i++)
{
if(n%i==0)
c=1;
}
if(c==0)
[Link]("It is a Prime");
else
[Link]("It is not a Prime");
}
}
OUTPUT
Enter the number
15
It is not a Prime
Experiment No 1
/*Armstrong Number*/
import [Link];
class armstrong
{
public static void main( String arg[])
{
int a, temp,r,b=0;
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
a=[Link]();
temp=a;
while(a>0)
{
r=a%10;
a=a/10;
b=b+(r*r*r);
}
if(temp==b)
{
[Link]("Armstrong Number");
}
else
{
[Link]("Not ARMSTRONG");
}
}
}
/*
Output:
enter the number
153
Armstrong Number
*/
Experiment No 1
/*palindrome number*/
import [Link];
class pallindrome
{
public static void main( String arg[])
{
int a, temp,r,b=0;
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
a=[Link]();
temp=a;
while(a>0)
{
r=a%10;
a=a/10;
b=b*10+r;
}
if(temp==b)
{
[Link]("PALLINDROME");
}
else
{
[Link]("NOT PALLINDROME");
}
}
}
/*Output
enter the number
121
PALLINDROME
*/