Advertisement
Guest User

QuadraticEquationsLoop

a guest
Dec 11th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package bg.unwe;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class QuadraticEquationsLoop {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         System.out.print("Limit: ");
  11.         int limitNumber = scanner.nextInt();
  12.  
  13.         for (int a = 1; a <= limitNumber; a++) {
  14.             for (int b = 1; b <= limitNumber; b++) {
  15.                 for (int c = 1; c <= limitNumber; c++) {
  16.                     System.out.println("a = " + a + ", b = " + b + ", c = " + c);
  17.  
  18.                     double d = Math.pow(b, 2) - 4 * a * c;
  19.  
  20.                     if (d < 0) {
  21.                         System.out.println("No solution");
  22.                     } else if (d == 0) {
  23.                         double x1 = -b / (2 * a);
  24.                         System.out.printf("x1 = %.1f\n", x1);
  25.                     } else if (d > 0) {
  26.                         double x1 = (-b - Math.sqrt(d)) / (2 * a);
  27.                         double x2 = (-b + Math.sqrt(d)) / (2 * a);
  28.  
  29.                         System.out.printf("x1 = %f\n", x1);
  30.                         System.out.printf("x2 = %f\n", x2);
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement