+ 5
Any better ways to shorten user inputs please?
// this is tedious i may need 20 of them đ Scanner scn = new Scanner(System.in); int input1 = scn.nextInt(); int input2 = scn.nextInt(); int input3 = scn.nextInt(); int input4 = scn.nextInt();
4 Answers
+ 32
use enhanced for loop //for making it more small & use if inside it to do a particular task for specified if condition
+ 12
Consider using array.
int [ ] inputs = new int[20];
for(int i=0; i<inputs.length; i++){
inputs[i] = scan.nextInt();
}
+ 12
You can access any element using index, but it's better to use loop. Your way is valid as well :) But loop will check all elements one by one.
for(int i=0; i<20; i++){
if(inputs[i] == 42){
// do something
}
}
+ 4
can i call a specific input with this?
like
if( input[2] == 42){System.out.print();}