Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IntroTasks {
- public static boolean is3Digit(int a) {
- return (a >= 100) && (a <= 999);
- }
- public static boolean isLast5(int a) {
- return (a % 10 == 5);
- }
- public static boolean isSameDigits(int a) {
- return (a % 10) == ((a / 10) % 10);
- }
- public static boolean isLeapYear(int a) {
- return (a % 400 == 0) || ((a % 4 == 0) && (a % 100 != 0));
- }
- public static String cat(int a) {
- //кот 1 21 31
- //кота 2 3 4 22 23 24 32 33 34
- //котов 5-20 25-30
- if (a % 10 == 1) {
- return "kot";
- }
- if ((a % 10 < 5) && (a % 10 > 1)) {
- return "kota";
- }
- return "kotov";
- }
- public static String getQuadraticEquationSolution(int a, int b, int c) {
- if (a == 0 && b == 0 && c == 0) {
- return "there are infinitely many solutions";
- }
- if (a == 0 && b == 0) {
- return "no solution";
- }
- if (a == 0) {
- return "one solution x = " + Double.toString(-c / (double)b);
- }
- double d = b * b - 4 * a * c;
- double sq = Math.sqrt(d);
- if (d < 0) {
- return "no solution";
- }
- if (d == 0) {
- return "one solution x = " + Double.toString(sq / a);
- }
- return "two solutions x1 = " + Double.toString(-sq / a) + ", x2 = " + Double.toString(sq / a);
- }
- public static boolean isPrimality(int a) {
- boolean flag = false;
- for (int x = 1; x * x <= a; x++) {
- flag |= (a % x == 0);
- }
- return !flag;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement