Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
6
Indexable
Never
import java.util.Random;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        System.out.print("Podaj liczbe rownan: ");
        int size = scanner.nextInt();
        int[] a = new int[size];
        int[] b = new int[size];
        int[] c = new int[size];
        int[] liczbaRownan = new int[size];

        for (int i = 0; i < size; i++) {
            a[i] = random.nextInt(20) - 10;
            b[i] = random.nextInt(20) - 10;
            c[i] = random.nextInt(20) - 10;
        }

        for(int i = 0; i < size; i++) {
            if(a[i] == 0) {
                if(b[i] != 0) liczbaRownan[i] = -1;
                else liczbaRownan[i] = 0;
            } else {
                int delta = b[i]*b[i] - 4 * a[i] * c[i];
                if(delta == 0) liczbaRownan[i] = 1;
                else if(delta > 0) liczbaRownan[i] = 2;
                else liczbaRownan[i] = 0;
            }
        }

        for(int i = 0; i < size; i++)
            System.out.println(a[i] + ", " + b[i] + ", " + c[i] + ": " + liczbaRownan[i]);
    }
}