0

Array input

for(int i=0;I<at.length;i++) { ar[i]=new int[sc.nextInt()]; } Generates an error saying incompatible types: int[] cannot be converted to int In the body of the loop.

13th Aug 2019, 3:24 PM
Utkarsh
Utkarsh - avatar
3 Answers
0
if you want input int and store it to int[] array: import ...Scanner.. ... int[] at = new int[5]; int[] r = new int[5]; // init sc ... for(int i=0; i<at.length; i++) //lowercase i< { r[i] = sc.nextInt(); }
13th Aug 2019, 6:07 PM
zemiak
+ 5
ar[i] denotes some value in array ar at index i, while new int [sc.nextInt()] denote some array of size sc.nextInt() so you can't store int array in int type variable Utkarsh can you provide full code, it will be helpful to understand program better
13th Aug 2019, 3:48 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
0
Can you suggest a solution to my problem
13th Aug 2019, 3:53 PM
Utkarsh
Utkarsh - avatar