Advertisement
NyanCoder

Контрольная.java

Jun 2nd, 2022
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MyClass {
  4.     private static double len(double x1, double y1, double x2, double y2) {
  5.         return Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  6.     }
  7.    
  8.     private static int factorial(int num) {
  9.         if (num == 1)
  10.             return 1;
  11.         return num * factorial(num - 1);
  12.     }
  13.    
  14.     public static void main(String args[]) {
  15.         // no1
  16.         Scanner sc = new Scanner(System.in);
  17.         int year = sc.nextInt();
  18.         sc.nextLine();
  19.         System.out.println(((year % 4 == 0) && (year % 100 != 0)) ? "YES" : "NO");
  20.        
  21.         // no2
  22.         int num = sc.nextInt();
  23.         sc.nextLine();
  24.         if (num < 2)
  25.             System.out.println("Число у вас неправильное");
  26.         else
  27.         {
  28.             boolean found = false;
  29.             for (int i = 2; i*i <= num; i++)
  30.             {
  31.                 if (num % i == 0)
  32.                 {
  33.                     System.out.println(i);
  34.                     found = true;
  35.                     break;
  36.                 }
  37.             }
  38.             if (!found)
  39.                 System.out.println(num);
  40.         }
  41.        
  42.         // no3
  43.         double x1 = sc.nextDouble(), y1 = sc.nextDouble(), x2 = sc.nextDouble(), y2 = sc.nextDouble(), x3 = sc.nextDouble(), y3 = sc.nextDouble();
  44.         sc.nextLine();
  45.         System.out.println(len(x1, y1, x2, y2) + len(x1, y1, x3, y3) + len(x2, y2, x3, y3));
  46.        
  47.         // no4
  48.         System.out.println(factorial(sc.nextInt()));
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement