mardi 29 juin 2021

How to change loop direction

I have 3x3 stars cube, but I make it can print continue as we want from our input, BUT it's loop Will go down, not go right, how to change to loop to the right

import java.util.scanner;

Public class program {
    Public static void main(String [] args) {
        Scanner getInp;
        int a;
        
        getInp = new Scanner(System.in);
        a = getInp.nextInt();

        for (int x=0; x<a; x++) {
            for (int y=0; y<3; y++) {
                for (int z=0; z<3; z++) {
                    System.out.print("* ");
                }
                System.out.println("\n");  
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire