0
How to get an array from user without knowing the number of elements in the array?
Array using C
6 Antworten
+ 3
use dynamic array ...
+ 2
The user have to enter number of elements and then enter the values.
Java:
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = scan.nextInt();
}
+ 2
On C++ use vectors.
+ 2
Use ArrayList in Java
+ 1
This code allocate and reallocate a buffer (C-String) as necessary to allow dynamically sized input. Maybe you can expand from the idea, and adjust to your fits.
https://code.sololearn.com/cViPoPhBTG48/?ref=app