+ 6

what is the problem in this program

import java.util.ArrayList; import java.util.Iterator; public class Program { public static void main(String[] args) { ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0 ;i<6 ; i++){ list.add(i); } int x=0; Iterator<Integer> it= list.Iterator(); while (it.hasNext) { x+=(it.next); } System.out.println(x); } }

27th Aug 2016, 4:44 AM
Anand Kumar
Anand Kumar - avatar
17 odpowiedzi
+ 5
15
14th Apr 2018, 11:49 AM
Osama
+ 3
what is the problem in this program import java.util.ArrayList; import java.util.Iterator; public class Program { public static void main(String[] args) { ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0 ;i<6 ; i++){ list.add(i); } int x=0; Iterator<Integer> it= list.Iterator(); while (it.hasNext) { x+=(it.next); } System.out.println(x); } } Answer :- 15
2nd Jul 2020, 6:27 AM
Gourav Tomar
Gourav Tomar - avatar
0
change it.hasNext to it.hasNext() also change it.next to it.next()
27th Aug 2016, 5:56 AM
Tiger
Tiger - avatar
0
change it.hasNext to it.hasNext() also change it.next to it.next() /*and the answer is 15
14th Jul 2017, 3:17 PM
PREM SHANKAR SINGH
PREM SHANKAR SINGH - avatar
0
15
29th Jan 2020, 4:30 PM
SHAIK AHAMMAD BASHA
0
15
1st Mar 2020, 4:18 AM
Shankar Ganesh
Shankar Ganesh  - avatar
0
15
7th Apr 2020, 4:13 AM
Hasini Uththara
0
15...
26th May 2020, 2:34 PM
Jahavid Allen
Jahavid Allen - avatar
0
try { File f = new File("a.txt"); Scanner sc = new (f); while (sc.hasNext()) { String a = .next(); String b = sc. (); System.out.println(a + " " + b); } sc. (); } catch (Exception e) { System.out.println("Error"); } sc close new next Scanner File Halpe Me
11th Jun 2020, 4:54 PM
Salem Mohamed
Salem Mohamed - avatar
0
Iterator integer iterator hasNext next
22nd Jun 2020, 4:10 PM
Mohamed Ghenia
Mohamed Ghenia - avatar
0
Drag and drop from the options below to read and print the content of the file a.txt, and then close it. try { File f = new File("a.txt"); Scanner sc = new (f); while (sc.hasNext()) { String a = .next(); String b = sc.(); System.out.println(a + " " + b); } sc.(); } catch (Exception e) { System.out.println("Error"); }
3rd Jul 2020, 4:14 AM
shaker farooqui
shaker farooqui - avatar
- 1
hasNext will be the hasNext()
24th Dec 2016, 8:54 AM
Nayan
Nayan - avatar
- 1
The answer is : 15
28th May 2018, 8:52 AM
Mohammadalaminsiam
Mohammadalaminsiam - avatar
- 1
Drag and drop from the options below to iterate and print all of the items in the list of Integers. < > it = list. (); while (it. ()) { System.out.println(it. ()); } Integer Iterator next iterator hasNext
9th Sep 2018, 11:44 AM
Rishav Dev
Rishav Dev - avatar
- 1
15
16th Sep 2019, 7:10 AM
PRATIK NAVALE
- 2
answer is 15
25th Aug 2018, 3:03 PM
Lokesh M. Pincha
Lokesh M. Pincha - avatar
- 3
< > it = list. (); while (it. ()) { System.out.println(it. ());
26th Mar 2019, 3:26 AM
angelo rusiana
angelo rusiana - avatar