样品运行:
请输入一个数字:1234567
洗牌后的号码是:4356271
样品运行:
请输入一个数字:1000001
洗牌后的号码是:0100100
答案 0 :(得分:0)
转换String中的数字使用此方法将字符串传递给它!
public void shuffle(String input){
List<Character> characters = new ArrayList<Character>();
for(char c:input.toCharArray()){
characters.add(c);
}
StringBuilder output = new StringBuilder(input.length());
while(characters.size()!=0){
int randPicker = (int)(Math.random()*characters.size());
output.append(characters.remove(randPicker));
}
System.out.println(output.toString());
}