f1lam3ntx0

nested class java

Dec 1st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4.  
  5. class lesson1{
  6.  public static void main(String[] args) {
  7.      int a,b,c;
  8.      System.out.println("enter two integer");
  9.      Scanner sn = new Scanner(System.in);
  10.      a= sn.nextInt();
  11.      b= sn.nextInt();
  12.      c=a+b;
  13.     System.out.println("the sum of the two given integer is: "+c);
  14.      
  15.       prime();
  16.      salary();
  17.     factorial();
  18.     weird();
  19.     pali();12
  20.      Avagdrow();
  21.     calculator();
  22.  }
  23.  
  24.  
  25. public static void prime()///////CODE FOR PRIME NUMBERS//////////
  26. {
  27.     int n;
  28.     Scanner ss = new Scanner(System.in);
  29.     System.out.println("enter a integer to know if it is prime number or not ");
  30.     n =ss.nextInt();
  31.     if (n%2==0) {
  32.         System.out.println("the integer is prime ");
  33.     } else {
  34.         System.out.println("the Interger is !prime ");
  35.     }
  36.  
  37. }
  38.  
  39.  
  40. public  static void salary()/////////CODE FOR BASIC SALARY //////////
  41. {
  42.     double sal;
  43.     double epf,hra,da,ta,netsal;
  44.     System.out.println("enter your current salary");
  45.     Scanner sc = new Scanner(System.in);
  46.     sal=sc.nextDouble();
  47.     hra=(sal*100/10);
  48.     epf=(sal*100/25);
  49.     ta=(sal*100/50);
  50.     da=(sal*100/12);
  51.     netsal=(hra+ta-da+epf);
  52.     System.out.println("the net salary is:"+netsal);
  53.    
  54.  
  55. }
  56.                  ////////////CODE FOR FACTORIAL OF A NUMBER///////////
  57. /public static void factorial()
  58. {
  59. int n,i;
  60. int fac = 1;
  61. Scanner sn =new Scanner(System.in);
  62. System.out.println("enter a integer for Factorial");
  63. n=sn.nextInt();
  64. for(i=1 ;i<=n; ++i)
  65. {
  66.     fac*=i;
  67.    
  68. }
  69. System.out.println("factorial:  "+fac);
  70. }
  71.            /////////////CODE FOR TWISTING DIGITS OF THE NUMBER///////////
  72. public static void weird()
  73. {
  74.     int num,rem;
  75.     int e=0 , o=0;
  76.     Scanner scc = new Scanner(System.in);
  77.     System.out.println("Enter an integer ");
  78.     num = scc.nextInt();
  79.     while(num>0){
  80.             rem=num%10;
  81.             if(rem%2==0)
  82.             {
  83.                 e++;
  84.             }
  85.             else{
  86.                 o++;
  87.             }
  88.             num=num/10;
  89.            
  90.     }
  91.  
  92.     System.out.println("H"+e  +o);
  93.  
  94.  
  95. }
  96.  
  97.             //////CODE FOR PALINDROME NUMBER///////////////
  98. public static void pali()
  99. {
  100.     int num,rem,k=0;
  101.      System.out.println("enter an integer");
  102.     Scanner scc = new Scanner(System.in);
  103.     num=scc.nextInt();
  104.     int y =  num;
  105.     while(num>0){
  106.         rem =num %10;
  107.         num =num /10;
  108.         k = (k *10)+rem;
  109.        
  110.     }
  111.     if (k==y) {
  112.         System.out.println("the  is palindrome");
  113.     } else {
  114.         System.out.println("the is ! palindrome");
  115.     }
  116.    
  117. }
  118.  
  119. public static void Avagdrow()////CODE FOR AVAGADROW NUMBER/////////
  120. {
  121.     int num,k,rem,A=0;
  122.     Scanner scc = new Scanner(System.in);
  123.     System.out.println("Enter an interger ");
  124.     num=scc.nextInt();
  125.     int y = num;
  126.     while(num>0)
  127.     {
  128.         rem=num%10;
  129.         num=num/10;
  130.         A=(rem*rem*rem)+A;
  131.     }
  132.     if (A==y) {
  133.         System.out.println("this is a Avagadrow number");
  134.     } else {
  135.         System.out.println("this ! a Avagadrow number");
  136.     }
  137. }
  138.  
  139.  
  140. public static long calculator()///////CODE FOR THE CALCULATOR //////////
  141. {
  142.  
  143.          int num1, num2, choice;
  144.  
  145.         Scanner sc = new Scanner(System.in);
  146.         boolean check = false;
  147.          do{
  148.  
  149.            System.out.println("Enter two integers: ");
  150.  
  151.            num1 = sc.nextInt();
  152.            num2 = sc.nextInt();
  153.            System.out.println("1: Addition");
  154.            System.out.println("2: Subtract");
  155.            System.out.println("4: Divide");
  156.            System.out.println("0: Quit");
  157.            System.out.println("Enter Choice: ");
  158.           choice = sc.nextInt();
  159.            if (choice == 1){
  160.  
  161.             System.out.println(num1 + num2);
  162.  
  163.            }else if (choice == 2){
  164.  
  165.              System.out.println(num1 - num2);
  166.  
  167.            }else if (choice == 3){
  168.  
  169.              System.out.println(num1 * num2);
  170.  
  171.            }else if (choice == 4){
  172.  
  173.              System.out.println(num1 / num2);
  174.  
  175.            }else if (choice == 0)
  176.             {
  177.  
  178.              System.out.println("This way to the exit.");
  179.  
  180.              System.exit(0);
  181.        
  182.             }else
  183.                 {
  184.  
  185.              System.out.println("Error, entered wrong number.");
  186.            }
  187.  
  188.       while (check==true);
  189.  
  190.        System.out.print("Finished.");
  191.  
  192.       }while (choice >= 5);
  193. return 0;
  194.      }    
  195.  
  196.      }
Add Comment
Please, Sign In to add comment