0
Can't convert String[] to int[],Why?
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); String b=sc.nextLine(); String[]b1=b.split(" "); int[] arr = new int[b1.length]; for (int i = 0; i < b1.length; i++) { arr[i] = Integer.parseInt(b1[i]); } } }
2 ответов
+ 1
For a perfect input, the problem lies because of the "int a = sc.nextInt()" statement.
By removing it, the program works nicely.
As after the "nextInt()", the program is accepting a null string "" as the error displays.
0
What input is being provided? If it's a sentence then the String won't convert to an Int.