So I am super new in terms of coding and java, I just started this week but am already stuck at a pretty simple problem. I am supposed to first check that there are only five integers that the user inputs (on the same line) - which I have tried to do and maybe succeeded?
But then, if the user does input five integers, I am supposed to make that input into an array with integers and I just have no idea how to do that. I tried to figure it out on my own but I simply didn't understand what to do. Could anyone explain this to me, I'd be very grateful!
Here is my (probably very lacking) code:
import java.util.Scanner;
public class Try2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String inputR = in.nextLine();
int lengthArgs = 5;
int nummer = (inputR.split(" ").length);
if(nummer == lengthArgs) {
//???
}
else {
System.out.println("Wrong");
}
}
}
inputR.split(" ")gives you 5 elements. 2) Change "nummer" tonumber(misspellings just look bad). 3) Usenew int[]. 4) Use Integer.praseInt()