0% found this document useful (0 votes)
37 views

Basic Python Program

The document contains code snippets for several Java programs that demonstrate different mathematical concepts: 1) A factorial program that takes user input for a number and calculates its factorial. 2) A Fibonacci series program that prints the first n numbers of the series based on user input. 3) A prime number checker that determines if a user input number is prime. 4) An Armstrong number checker that identifies if a number is an Armstrong number. 5) A palindrome checker that verifies if a number is a palindrome. Each program outputs the result of running it with sample input values provided.

Uploaded by

Abhi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Basic Python Program

The document contains code snippets for several Java programs that demonstrate different mathematical concepts: 1) A factorial program that takes user input for a number and calculates its factorial. 2) A Fibonacci series program that prints the first n numbers of the series based on user input. 3) A prime number checker that determines if a user input number is prime. 4) An Armstrong number checker that identifies if a number is an Armstrong number. 5) A palindrome checker that verifies if a number is a palindrome. Each program outputs the result of running it with sample input values provided.

Uploaded by

Abhi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment No 1

/*factorial*/
import java.util.Scanner;

class Factorial
{
public static void main(String args[])
{
int n, c, fact = 1;

System.out.println("Enter an integer to calculate it's factorial");


Scanner sc= new Scanner(System.in);

n = sc.nextInt();

if (n < 0)
System.out.println("Number should be non-negative.");
else
{
for (c = 1; c <= n; c++)
fact = fact*c;

System.out.println("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 java.util.Scanner;
class fib
{
public static void main(String rg[ ])
{
int a,b=1,c=0,n,i=1;
Scanner sc= new Scanner(System.in);
System.out.println("How many number want in fibonacci series?");
n=sc.nextInt();
System.out.printf("Fibonacci serie of first %d number\n",n);
while(i<=n)
{
System.out.print(" "+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 java.util.Scanner;
class prime
{
public static void main (String args[])
{
int n,i,c=0;
System.out.println("Enter the number");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=2;i<n;i++)
{
if(n%i==0)
c=1;
}
if(c==0)
System.out.println("It is a Prime");
else
System.out.println("It is not a Prime");
}
}

OUTPUT
Enter the number
15
It is not a Prime
Experiment No 1
/*Armstrong Number*/
import java.util.Scanner;
class armstrong
{
public static void main( String arg[])
{
int a, temp,r,b=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the number");
a=sc.nextInt();
temp=a;
while(a>0)
{
r=a%10;
a=a/10;
b=b+(r*r*r);
}
if(temp==b)
{
System.out.println("Armstrong Number");

}
else
{
System.out.println("Not ARMSTRONG");

}
}
}
/*
Output:
enter the number
153
Armstrong Number
*/
Experiment No 1

/*palindrome number*/
import java.util.Scanner;
class pallindrome
{
public static void main( String arg[])
{
int a, temp,r,b=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the number");
a=sc.nextInt();
temp=a;
while(a>0)
{
r=a%10;
a=a/10;
b=b*10+r;
}
if(temp==b)
{
System.out.println("PALLINDROME");

}
else
{
System.out.println("NOT PALLINDROME");

}
}
}

/*Output
enter the number
121
PALLINDROME
*/

You might also like