+ 3

Whats wrong in my code?

public class practice { public static void main(String[] args) { double myArray[] = {2.5,4.1,18.1,22.3}; double sum = 0.0; for(int x = 0; x < 4;x++); { sum += myArray[x]; } } System.out.println(sum); } The code give me an error. /practice.java:12: error: <identifier> expected System.out.println(sum); /practice.java:9: error: cannot find symbol sum += myArray[x]; plz explain the whole code.

5th Sep 2018, 9:37 AM
Nitin Gutte
Nitin Gutte - avatar
4 Réponses
+ 3
move the print statement inside main()
5th Sep 2018, 10:15 AM
JME
+ 1
Another error . /practice.java:9: error: cannot find symbol sum += myArray[x];
5th Sep 2018, 11:34 AM
Nitin Gutte
Nitin Gutte - avatar
+ 1
behind the normal braces of the for loop, remove that semicolon:)
5th Sep 2018, 2:22 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Thank u guyz...
5th Sep 2018, 4:27 PM
Nitin Gutte
Nitin Gutte - avatar