Cristiano Magro
2025-10-04 a70c2252becc1e607305909a2230257847c57455
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class RelativamentePrimo {
 
    public static void main(String[] args) {
 
        if (args.length < 1) {
            System.out.println("Errore: devi fornire un numeri intero come argomento.");
            return;
        }
 
        int numero = Integer.parseInt(args[0]);
 
        for (int i = 1; i <= numero; i++) {
            for (int j = 1; j <= numero; j++) {
                if (gcd(i, j) == 1) {
                    System.out.print("* ");
                } else {
                    System.out.print("  ");
                }
            }
            System.out.println();
        }
    }
 
    // Metodo per calcolare il massimo comun divisore (Euclide)
    public static int gcd(int a, int b) {
        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }
}