mardi 29 septembre 2020

Scramble each digit of the int a and print out the biggest possible integer

I’m stuck here. Do I just keep making new strings and turn them to int or us there a faster better way?

public void biggest(int a){
       int random;
       String aS = String.valueOf(a);
       int ah=9;
       if (a<10)
             System.out.println(a);
       for(int i= 0;i<aS.length();i++){
            String firstNum = aS.substring(i,i+1);
            for (int j = ah; j > Integer.parseInt(firstNum); j--){
                System.out.println(ah);
            
            }
            }
    } ```



Aucun commentaire:

Enregistrer un commentaire