- 1

how to input array using scanner

12th Oct 2020, 10:13 AM
IKHWAN HABIBI
IKHWAN HABIBI - avatar
4 Answers
+ 4
Use for loop and write input statement in loop body import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); for(int i=1;i<5;i++) System.out.println(myVar.nextLine()); } }
12th Oct 2020, 10:29 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
ArrayList<Integer> obj = new ArrayList<>(); Scanner sc = new Scanner(System.in); while(sc.hasNextInt()) { obj.add(sc.nextInt()); }
12th Oct 2020, 12:04 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
U can use a loop.
12th Oct 2020, 10:14 AM
Steve Sajeev
Steve Sajeev - avatar
0
Ya
12th Oct 2020, 10:19 AM
IKHWAN HABIBI
IKHWAN HABIBI - avatar