I am new to java and I am still getting used to most of the syntax. Here I tried to get two inputs (the first one being an int and the second one a string) and later one I do some calculations with them. But when I run the program, it gives this message:
Exception in thread "main" java.lan._NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NuthberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at Main.main(Main.java:13)
.
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String args[]) {
Scanner myObj = new Scanner(System.in);
int N = myObj.nextInt();
String Input = myObj.nextLine();
String[] Inputs = Input.split(" ", 0);
int size = Inputs.length;
int[] a = new int[size];
for (int i = 0; i < size; i++) {
a[i] = Integer.parseInt(Inputs[i]);
}
}
}
My understanding is that the program is assuming both inputs as the same. But how do I fix that?