Thursday, 21 September 2017

Factorial-Fibo-Palindrome-Prime-Armstrong Programs in Java


= = = = = = = = = = = = = = = = = = = =
PROGRAM  :  1  Find Factorial
= = = = = = = = = = = = = = = = = = = =


import java.util.*;
class fact
{
 public static void main(String args[])
 {  
  int a,i,b=1;
 
  Scanner sc = new Scanner(System.in);
 
  System.out.println("Enter the number of factorial:");
  a = sc.nextInt();
  for(i=1;i<=a;i++)
  {
   b=b*i;
  }
  System.out.println("Your Factorial is:" + b);
 }
}


= = = = = = = = = = = = = = = = = = = =
PROGRAM : 2 Palindrome Number
= = = = = = = = = = = = = = = = = = = =



import java.util.*;
class palindrome
{
 public static void main(String args[])

 { Scanner sc=new Scanner(System.in);
  System.out.println("Enter Number for palindrome:");
  int iNum=sc.nextInt();
  int iPal=0;
  int iNum2=iNum;
  while(iNum!=0)
  {
   iPal=(iPal*10)+(iNum%10);
   iNum=iNum/10;
  }
  if(iNum2==iPal)
  {
   System.out.println(iNum2+" is palingdrome");
  }
  else
  {
   System.out.println(iNum2+" is not palingdrome");
  }
 }
}


= = = = = = = = = = = = = = = = = = = =
PROGRAM : 3 : Fibo Series or Fibonacci sequence
= = = = = = = = = = = = = = = = = = = =



import java.util.*;

class fibo
{
 public static void main(String args[])
 {
  int i,a,b,c,d;
  Scanner sc = new Scanner(System.in);
  System.out.println("enter limit : ");
  d= sc.nextInt();
  a=0;
  b=1;
  System.out.print(a+",");
  System.out.print(b);
  for(i=1;i<=d;i++)
  {
   c=a+b;
   System.out.print(","+c);
   a=b;
   b=c;
  }
 }
}



= = = = = = = = = = = = = = = = = = = =
PROGRAM : 4 Prime Number
= = = = = = = = = = = = = = = = = = = =



import java.util.*;

class Prime
{  
 public static void main(String args[])
 {  
  int i,m=0,count=0;    
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.println("enter Number : ");
  num= sc.nextInt();

  for(i=1;i<=num;i++)
  {    
   if(num%i==0)
   {    
    count=count+1;   
   }     
  }    
  if(count==2)
  {
   System.out.println("Number is prime");    
  }
  else
  {
   System.out.println("Number is Not prime");    
  } 
 }  
}  


= = = = = = = = = = = = = = = = = = = =
PROGRAM : 5 Armstrong Number
= = = = = = = = = = = = = = = = = = = =




import java.util.*;
class armstrong
{
 public static void main(String args[])
 { Scanner sc=new Scanner(System.in);
  System.out.println("Enter Number for Armstrong:");
  int iNum=sc.nextInt();
  int iArms=0;
  int iNum2=iNum;
  while(iNum!=0)
  {
   iArms=iArms+(iNum%10)*(iNum%10)*(iNum%10);
   iNum=iNum/10;
  }
  if(iNum2==iArms)
  {
   System.out.println("number is amstrong");
  }
  else
  {
   System.out.println("number is not amstrong");
  }
 }
}


0 comments:

Post a Comment