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

后端 未结 4 485
孤独总比滥情好
孤独总比滥情好 2021-01-29 15:15

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;
       Stri         


        
4条回答
  •  北海茫月
    2021-01-29 15:35

        String useMe = Integer.toString(argumentOne);
        int rMe = argumentOne;
     
        int x = 0;
        while (x != 1000) {
          int i = 0;
          String returnMe = "";
          String inUse = useMe;
          while (i != useMe.length()) {
            Random random = new Random();
            int index = random.nextInt(inUse.length());
            returnMe = returnMe + inUse.charAt(index);
            inUse = inUse.substring(0, index) + inUse.substring(index + 1);
            i++;
          }
          if (Integer.parseInt(returnMe) > rMe) {
            rMe = Integer.parseInt(returnMe);
          }
          x++;
        }
     
        System.out.print( rMe );
     
      }
    

提交回复
热议问题