+ 1

Is it possible to take length of array from user then initialize array of that length

Array have a specific length, is it possible to create the array according to the user I always initialize array of 100 elements, but what happened if user want to enter more than 100 elements, then I have to change value from 100 to more than hundred

22nd Jan 2018, 4:14 AM
VISHAL BISWAS
VISHAL BISWAS - avatar
1 Respuesta
+ 2
Yes abcurce you can just take variable and initialize it and give a message of please enter the length than put the variable to the array container. eg:- Scanner sc=new Scanner (System.in); System.out.print("Enter the length of array"); int a=sc.nextInt(); int b[]=new int[a]; // putting the initialize value. and start the process.
22nd Jan 2018, 4:36 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar