0

Allocated while loop results

how do I add the while loop results to an array list or array. like 10 have it's own location in an array list or have it's own index in an array. https://code.sololearn.com/cOV9ym714MtR/?ref=app https://code.sololearn.com/cOV9ym714MtR/?ref=app

28th Jul 2019, 6:05 PM
Sibusiso Mbambo
1 ответ
+ 1
import java.util.ArrayList; ArrayList<Integer> myList = new ArrayList<>(); instead of the print statement in the while loop: myList.add(i); After that you can print the list: System.out.println(myList); Array: int[] arr = new int[9] int i = 10; int j = 0; //index of array starts with 0 while(i > 1){ arr[j] = i; i--; } //enhanced for loop to print the array for(int value : arr){ System.out.println(value); }
28th Jul 2019, 7:30 PM
Denise Roßberg
Denise Roßberg - avatar