Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bg.unwe;
- import java.util.Scanner;
- public class QuadraticEquationsLoop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Limit: ");
- int limitNumber = scanner.nextInt();
- for (int a = 1; a <= limitNumber; a++) {
- for (int b = 1; b <= limitNumber; b++) {
- for (int c = 1; c <= limitNumber; c++) {
- System.out.println("a = " + a + ", b = " + b + ", c = " + c);
- double d = Math.pow(b, 2) - 4 * a * c;
- if (d < 0) {
- System.out.println("No solution");
- } else if (d == 0) {
- double x1 = -b / (2 * a);
- System.out.printf("x1 = %.1f\n", x1);
- } else if (d > 0) {
- double x1 = (-b - Math.sqrt(d)) / (2 * a);
- double x2 = (-b + Math.sqrt(d)) / (2 * a);
- System.out.printf("x1 = %f\n", x1);
- System.out.printf("x2 = %f\n", x2);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement