Advertisement
nq1s788

Untitled

Sep 4th, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. public class IntroTasks {
  2.     public static boolean is3Digit(int a) {
  3.         return (a >= 100) && (a <= 999);
  4.     }
  5.  
  6.     public static boolean isLast5(int a) {
  7.         return (a % 10 == 5);
  8.     }
  9.  
  10.     public static boolean isSameDigits(int a) {
  11.         return (a % 10) == ((a / 10) % 10);
  12.     }
  13.  
  14.     public static boolean isLeapYear(int a) {
  15.         return (a % 400 == 0) || ((a % 4 == 0) && (a % 100 != 0));
  16.     }
  17.  
  18.     public static String cat(int a) {
  19.         //кот 1 21 31
  20.         //кота 2 3 4 22 23 24 32 33 34
  21.         //котов 5-20 25-30
  22.         if (a % 10 == 1) {
  23.             return "kot";
  24.         }
  25.         if ((a % 10 < 5) && (a % 10 > 1)) {
  26.             return "kota";
  27.         }
  28.         return "kotov";
  29.     }
  30.  
  31.     public static String getQuadraticEquationSolution(int a, int b, int c) {
  32.         if (a == 0 && b == 0 && c == 0) {
  33.             return "there are infinitely many solutions";
  34.         }
  35.         if (a == 0 && b == 0) {
  36.             return "no solution";
  37.         }
  38.         if (a == 0) {
  39.             return "one solution x = " + Double.toString(-c / (double)b);
  40.         }
  41.         double d = b * b - 4 * a * c;
  42.         double sq = Math.sqrt(d);
  43.         if (d < 0) {
  44.             return "no solution";
  45.         }
  46.         if (d == 0) {
  47.             return "one solution x = " + Double.toString(sq / a);
  48.         }
  49.         return "two solutions x1 = " + Double.toString(-sq / a) + ", x2 = " + Double.toString(sq / a);
  50.     }
  51.  
  52.     public static boolean isPrimality(int a) {
  53.         boolean flag = false;
  54.         for (int x = 1; x * x <= a; x++) {
  55.             flag |= (a % x == 0);
  56.         }
  57.         return !flag;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement