+ 1
Is there a way to create a code that can choose a random case?
8 Respuestas
+ 1
give more information. of course you can generate random numbers and randomly choose one for example.
+ 1
like in this code I have numerous cases where the user has to input something such as '2' or '3' or '4'. I was wondering if it was possible to create a code that can chooses randomly which case to go through and follow what ever is in that case?
https://code.sololearn.com/c5BL4rb1UACd/?ref=app
0
i gave him one example. now it's his turn to explain what this program should be about. there are not only ways to generate random integers, also strings and others as you hopefully know.
0
I was thinking of doing something along the lines of this (obviously not finished) I just dont know how to get the code to understand that 2, 3, and 4 are cases not a word or string.
case "random case":
Random random = new Random();
String [] cases = {"2", "3", "4"};
int gg = random.nextInt(cases.length);
String randomcase = cases[gg];
System.out.println(randomcase);
0
Use switch, break and default
0
instead of this or do I add on to it?