Advertisement
BERKYT

LABA 1 KSIPO

Nov 17th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.92 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main
  6. {
  7.  
  8.     public static void main(String[] args)
  9.     {
  10.         Scanner in  = new Scanner(System.in);
  11.  
  12.         while(true){
  13.  
  14.             String check = in.nextLine();
  15.  
  16.             switch(check){
  17.                 case"1":
  18.                     ex1();
  19.                     break;
  20.                 case"2":
  21.                     ex2();
  22.                     break;
  23.                 case"3":
  24.                     ex3();
  25.                     break;
  26.                 case"4":
  27.                     ex4();
  28.                     break;
  29.                 case"5":
  30.                     ex5();
  31.                     break;
  32.                 case"6":
  33.                     ex6();
  34.                     break;
  35.                 case"exit":
  36.                     return;
  37.  
  38.             }
  39.         }
  40.     }
  41.     public static void ex1()
  42.     {
  43.  
  44.         Scanner in  = new Scanner(System.in);
  45.  
  46.         int count = in.nextInt();
  47.  
  48.         double[] array = new double[count];
  49.  
  50.         for(int i = 0; i < count; i++)
  51.         {
  52.             array[i] = Math.random();
  53.             System.out.println(array[i]);
  54.         }
  55.  
  56.         double max = array[0];
  57.         double min = array[0];
  58.         double center = 0;
  59.         for(int i = 0; i < count; i++)
  60.         {
  61.             if(max < array[i])
  62.             {
  63.                 max = array[i];
  64.             }
  65.             if(min > array[i])
  66.             {
  67.                 min = array[i];
  68.             }
  69.             center += array[i];
  70.         }
  71.         center = center/array.length;
  72.         System.out.println("MAX: " + max);
  73.         System.out.println("MIN: " + min);
  74.         System.out.println("CENTER: " + center);
  75.     }
  76.     public static void ex2()
  77.     {
  78.  
  79.         Scanner in  = new Scanner(System.in);
  80.  
  81.         int count = 13;
  82.         int x = 0;
  83.         while(count > 12 || count < 1)
  84.         {
  85.             if (x > 0 && count > 12)
  86.                 System.out.print("You entered too much value");
  87.             else if (x > 0 && count < 1)
  88.                 System.out.print("You entered too small a value");
  89.             ++x;
  90.  
  91.             try{
  92.                 count = in.nextInt();
  93.             }
  94.             catch (Exception e){
  95.                 System.out.println("You entered an invalid value " + e.getMessage());
  96.                 return;
  97.             }
  98.         }
  99.  
  100.         if(count > 11 || count < 3)
  101.         {
  102.             System.out.print("Winter");
  103.         }
  104.         else if(count > 2 || count < 6)
  105.         {
  106.             System.out.print("Spring");
  107.         }
  108.         else if(count > 5 || count < 9)
  109.         {
  110.             System.out.print("Summer");
  111.         }
  112.         else if(count > 8 || count < 12)
  113.         {
  114.             System.out.print("Autumn");
  115.         }
  116.     }
  117.     public static void ex3()
  118.     {
  119.         Scanner in  = new Scanner(System.in);
  120.  
  121.         double number = in.nextInt();
  122.  
  123.         while(number != 2)
  124.         {
  125.             System.out.println(number);
  126.             number = number/2;
  127.             if (number < 2)
  128.             {
  129.                 break;
  130.             }
  131.         }
  132.         if (number == 2)
  133.         {
  134.             System.out.print("YES");
  135.         }
  136.         else if (number != 2)
  137.         {
  138.             System.out.print("NO");
  139.         }
  140.         System.out.print(number);
  141.     }
  142.     public static void ex4()
  143.     {
  144.         Scanner in  = new Scanner(System.in);
  145.  
  146.         int num = in.nextInt();
  147.         int factorial = 1;
  148.  
  149.         for(int i = 1; i < num+1; i++)
  150.         {
  151.             factorial *= i;
  152.         }
  153.         System.out.print(factorial);
  154.  
  155.     }
  156.     public static void ex5()
  157.     {
  158.         Scanner in  = new Scanner(System.in);
  159.  
  160.         int number = in.nextInt();
  161.         int num = number;
  162.         char[] c_array = new  char[4];
  163.         int x = 1;
  164.  
  165.         while(x < 12 && num < 9000)
  166.         {
  167.             num++;
  168.             String s_num = Integer.toString(num);
  169.  
  170.             for(int i = 0; i < 4; i++)
  171.             {
  172.                 c_array[i] = s_num.charAt(i);
  173.                 //System.out.print(c_array[i]);
  174.             }
  175.             for(int i = 0; i < 4; i++)
  176.             {
  177.                 for(int j = 0; j < 4; j++)
  178.                 {
  179.                     if(i == j)
  180.                     {
  181.  
  182.                     }
  183.                     else if(c_array[i] != c_array[j])
  184.                     {
  185.                         ++x;
  186.                     }
  187.                     else
  188.                     {
  189.                         x = 1;
  190.                         continue;
  191.                     }
  192.                 }
  193.             }
  194.         }
  195.         System.out.print(num);
  196.     }
  197.     public static void ex6()
  198.     {
  199.         int n1 = 1;
  200.         int n2 = 1;
  201.         int n3 = 1;
  202.  
  203.         System.out.print(n1+" "+" "+n2+" ");
  204.         for(int i = 0; i < 9; i++)
  205.         {
  206.             n3 = n1+n2;
  207.             System.out.print(n3+" ");
  208.             n1 = n2;
  209.             n2 = n3;
  210.         }
  211.     }
  212. }
  213.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement