1
Hello, this code returns 6 values between 1 and 60 without repeating and in order. But for numbers smaller than 10 I would like to add 0 before type: 01,02...10. I tried using String.format() but it gives error when compiling.
Thanks.
private static String sortear() {
Set<Integer> numberset = new HashSet<>();
Random random = new Random();
while (numberset.size() < 6) {
numberset.add((random.nextInt(60) + 1));
}
ArrayList<Integer> jogo = new ArrayList<>(numberset);
Collections.sort(jogo);
String vetor = Arrays.toString(jogo.toArray());
return vetor;
}
This part of the code has nothing to do with the error you describe in the question. The part where you give the error you have not posted. Post it so we can see where the error is and how we can help. And show the error too, the more useful information you give the more chances we have to help.
– Maniero
It’s what I’m doing for Android Studio, when I add at the end of the code : Return String.format( Format.GAME, vector); The error is this: FATAL EXCEPTION: main java.util.Illegalformatconversionexception: %d can’t format java.util.Arraylist Arguments
– Murillo Comino