Advertisement
desant74268

HW_IF

Oct 21st, 2021
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package ru.itsjava;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class IfHW {
  6.     public static void main(String[] args) {
  7.         Scanner console = new Scanner(System.in);
  8.  
  9. //        System.out.println("Введите число A: ");
  10. //        int a = console.nextInt();
  11. //        System.out.println("Число А = " + a);
  12. //        System.out.println("\nВведите число B: ");
  13. //        int b = console.nextInt();
  14. //        System.out.println("Число B = " + b);
  15. //
  16. //
  17. //        System.out.println("1. Max.");
  18. //        if (a > b) {
  19. //            System.out.println("Max: A = " + a);
  20. //        } else {
  21. //            System.out.println("Max: B = " + b);
  22. //        }
  23.  
  24.  
  25. //        System.out.println("Введите число A: ");
  26. //        int a = console.nextInt();
  27. //        System.out.println("Число А = " + a);
  28. //        System.out.println("\nВведите число B: ");
  29. //        int b = console.nextInt();
  30. //        System.out.println("Число B = " + b);
  31. //        System.out.println("\nВведите число C: ");
  32. //        int c = console.nextInt();
  33. //        System.out.println("Число C = " + c);
  34. //
  35. //        System.out.println("2. Min.");
  36. //        if (a <= b && a <= c) {
  37. //            System.out.println("Min: A = " + a);
  38. //        }
  39. //        else if (b <= c && b <= a) {
  40. //            System.out.println("Min: B = " + b);
  41. //        }
  42. //        else if (c <= b && c <= a) {
  43. //            System.out.println("Min: C = " + c);
  44. //        }
  45.  
  46. //        System.out.println("3. Prizivnik");
  47. //        System.out.println("Input Age:");
  48. //        int age = console.nextInt();
  49. //        System.out.println("Age: " + age);
  50. //
  51. //        if (age<=0 || age>=100){
  52. //            System.out.println("Age error!");
  53. //        }
  54. //        else if (age>0 && age<18){
  55. //            System.out.println("Early");
  56. //        }
  57. //        else if (age>=18 && age<=27){
  58. //            System.out.println("Welcom to the ARMY! ");
  59. //        }
  60. //        else if (age>27 && age<100){
  61. //            System.out.println("Late!");
  62. //        }
  63.  
  64. //        System.out.println("5. SWAP");
  65. //        System.out.println("Input num1");
  66. //        int num1 = console.nextInt();
  67. //        System.out.println("Input num2");
  68. //        int num2 = console.nextInt();
  69. //        System.out.println("num1 = " + num1);
  70. //        System.out.println("num2 = " + num2);
  71. //        System.out.println("swap solution");
  72. //
  73. //        int temp = num1;
  74. //        num1 = num2;
  75. //        num2 = temp;
  76. //        System.out.println("num1 = " + num1);
  77. //        System.out.println("num2 = " + num2);
  78.  
  79.  
  80.         System.out.println("6. Quadratic equation");
  81.         System.out.println("Input coefficients");
  82.         System.out.println("Input A:");
  83.         double a = console.nextDouble();
  84.         System.out.println("Input B:");
  85.         double b = console.nextDouble();
  86.         System.out.println("Input C:");
  87.         double c = console.nextDouble();
  88.         System.out.println(a + "x^2 + " + b + "x + " + c + " = 0");
  89.         System.out.println("solution");
  90.         double d = (b * b) - (4 * a * c);
  91.         if (d > 0) {
  92.             System.out.println("two roots:");
  93.             System.out.println("x1 = " + ((-b + Math.sqrt(d)) / (2 * a)));
  94.             System.out.println("x2 = " + ((-b - Math.sqrt(d)) / (2 * a)));
  95.         } else if (d == 0) {
  96.             System.out.println("one root:");
  97.             double x = (((-1) * b) / (2 * a));
  98.             System.out.println("x = " + x);
  99.         } else if (d < 0) {
  100.             System.out.println("Quadratic equation don't have roots");
  101.         }
  102.  
  103.     }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement