prime number program
package prime_number;
import java.util.*;
public class Prime_number {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" enter number ");
int num = sc.nextInt();
int count = 0;
for(int i=2; i<num; i++)
{
if(num%i==0)
{
count=1;
break;
}
}
if(count==1)
{
System.out.println(num+" is not a prime number \nThank u!!!");
}
else
{
System.out.println(num+" is a prime number \nThank u!!!");
}
}
}
fibonacci_series
package fibonacci_series;
//1 1 2 3 5 8 11......n
import java.util.*;
public class Fibonacci_series {
public static void main(String[] args) {
int k,a=1,b=1;
Scanner sc= new Scanner(System.in);
System.out.println("enter number till that you want to add last two digit");
int n= sc.nextInt();
k=0;
System.out.print("1 1");
while(k<=n)
{
k=a+b;
System.out.print(" "+k);
a=b;
b=k;
}
}
}
factorial
package factorial;
import java.util.*;
public class Factorial {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
System.out.println("enetr number");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("negative number cant be entered");
}
else{
int fact=1;
for(int k=1;k<=n;k++)
{
fact=fact*k;
}
System.out.print(" "+fact+" ");
}
}
}
Palindrome
package palindrome;
import java .util.*;
public class Palindrome {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("enter number");
int n = sc.nextInt();
int r,s=0;
int temp=n;
while(n>0)
{
r=n%10;
n=n/10;
s=s*10+r;
}
if(temp==s)
{
System.out.println("palindrome");
}
else{
System.out.println("srry bhai nhi hai");
}
}
}
package prime_number;
import java.util.*;
public class Prime_number {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" enter number ");
int num = sc.nextInt();
int count = 0;
for(int i=2; i<num; i++)
{
if(num%i==0)
{
count=1;
break;
}
}
if(count==1)
{
System.out.println(num+" is not a prime number \nThank u!!!");
}
else
{
System.out.println(num+" is a prime number \nThank u!!!");
}
}
}
fibonacci_series
package fibonacci_series;
//1 1 2 3 5 8 11......n
import java.util.*;
public class Fibonacci_series {
public static void main(String[] args) {
int k,a=1,b=1;
Scanner sc= new Scanner(System.in);
System.out.println("enter number till that you want to add last two digit");
int n= sc.nextInt();
k=0;
System.out.print("1 1");
while(k<=n)
{
k=a+b;
System.out.print(" "+k);
a=b;
b=k;
}
}
}
factorial
package factorial;
import java.util.*;
public class Factorial {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
System.out.println("enetr number");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("negative number cant be entered");
}
else{
int fact=1;
for(int k=1;k<=n;k++)
{
fact=fact*k;
}
System.out.print(" "+fact+" ");
}
}
}
Palindrome
package palindrome;
import java .util.*;
public class Palindrome {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("enter number");
int n = sc.nextInt();
int r,s=0;
int temp=n;
while(n>0)
{
r=n%10;
n=n/10;
s=s*10+r;
}
if(temp==s)
{
System.out.println("palindrome");
}
else{
System.out.println("srry bhai nhi hai");
}
}
}