lundi 12 octobre 2020

I want to create a pattern of nxn in java with the help of loops

I want to create a pattern like this, why is this code wrong?

x x x x

x x x

x x

x for any value of n( its a nxn pattern )

Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for (int i = n; i <= n; i--) {
        for (int j = 1; j <= i; j++) {
            System.out.print("* ");
        }
        System.out.println();
    }

}

}

Aucun commentaire:

Enregistrer un commentaire