mercredi 2 octobre 2019

how to order a string array in a loop with if function in a table

i want to order a random size in array to table use looping and if function or something more easier

the array is (id success to print this to table)

smallest | biggest  | medium   | big     | small 
small | smallest | medium | biggest | big
biggest | small | big | medium | smallest
medium | big | smallest | small | big
small | smallest | medium | biggest | big
    String cow[][] = new String[5][5];

    for(int j=0;j<cow.length;j++){
        for(int i=0;i<cow[j].length;i++){
            if (cow[i][j] == "smallest"){
                System.out.print ("| "+cow[i][j]+" |");
            }
            else if (cow[i][j] == "small"){
                System.out.print ("| "+cow[i][j]+" |");
            }
            else if (cow[i][j] == "medium"){
                System.out.print ("| "+cow[i][j]+" |");
            }
            else if (cow[i][j] == "big"){
                System.out.print ("| "+cow[i][j]+" |");
            }
            else if (cow[i][j] == "biggest"){
                System.out.print ("| "+cow[i][j]+" |");
            }
        }
        System.out.println ();
    }

what i expected


smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest

please help me:(

Aucun commentaire:

Enregistrer un commentaire