Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- while(true){
- String check = in.nextLine();
- switch(check){
- case"1":
- ex1();
- break;
- case"2":
- ex2();
- break;
- case"3":
- ex3();
- break;
- case"4":
- ex4();
- break;
- case"5":
- ex5();
- break;
- case"6":
- ex6();
- break;
- case"exit":
- return;
- }
- }
- }
- public static void ex1()
- {
- Scanner in = new Scanner(System.in);
- int count = in.nextInt();
- double[] array = new double[count];
- for(int i = 0; i < count; i++)
- {
- array[i] = Math.random();
- System.out.println(array[i]);
- }
- double max = array[0];
- double min = array[0];
- double center = 0;
- for(int i = 0; i < count; i++)
- {
- if(max < array[i])
- {
- max = array[i];
- }
- if(min > array[i])
- {
- min = array[i];
- }
- center += array[i];
- }
- center = center/array.length;
- System.out.println("MAX: " + max);
- System.out.println("MIN: " + min);
- System.out.println("CENTER: " + center);
- }
- public static void ex2()
- {
- Scanner in = new Scanner(System.in);
- int count = 13;
- int x = 0;
- while(count > 12 || count < 1)
- {
- if (x > 0 && count > 12)
- System.out.print("You entered too much value");
- else if (x > 0 && count < 1)
- System.out.print("You entered too small a value");
- ++x;
- try{
- count = in.nextInt();
- }
- catch (Exception e){
- System.out.println("You entered an invalid value " + e.getMessage());
- return;
- }
- }
- if(count > 11 || count < 3)
- {
- System.out.print("Winter");
- }
- else if(count > 2 || count < 6)
- {
- System.out.print("Spring");
- }
- else if(count > 5 || count < 9)
- {
- System.out.print("Summer");
- }
- else if(count > 8 || count < 12)
- {
- System.out.print("Autumn");
- }
- }
- public static void ex3()
- {
- Scanner in = new Scanner(System.in);
- double number = in.nextInt();
- while(number != 2)
- {
- System.out.println(number);
- number = number/2;
- if (number < 2)
- {
- break;
- }
- }
- if (number == 2)
- {
- System.out.print("YES");
- }
- else if (number != 2)
- {
- System.out.print("NO");
- }
- System.out.print(number);
- }
- public static void ex4()
- {
- Scanner in = new Scanner(System.in);
- int num = in.nextInt();
- int factorial = 1;
- for(int i = 1; i < num+1; i++)
- {
- factorial *= i;
- }
- System.out.print(factorial);
- }
- public static void ex5()
- {
- Scanner in = new Scanner(System.in);
- int number = in.nextInt();
- int num = number;
- char[] c_array = new char[4];
- int x = 1;
- while(x < 12 && num < 9000)
- {
- num++;
- String s_num = Integer.toString(num);
- for(int i = 0; i < 4; i++)
- {
- c_array[i] = s_num.charAt(i);
- //System.out.print(c_array[i]);
- }
- for(int i = 0; i < 4; i++)
- {
- for(int j = 0; j < 4; j++)
- {
- if(i == j)
- {
- }
- else if(c_array[i] != c_array[j])
- {
- ++x;
- }
- else
- {
- x = 1;
- continue;
- }
- }
- }
- }
- System.out.print(num);
- }
- public static void ex6()
- {
- int n1 = 1;
- int n2 = 1;
- int n3 = 1;
- System.out.print(n1+" "+" "+n2+" ");
- for(int i = 0; i < 9; i++)
- {
- n3 = n1+n2;
- System.out.print(n3+" ");
- n1 = n2;
- n2 = n3;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement