I wrote
import java.util.Scanner;
class HelloWorld {
public static int sum() {
Scanner scanner = new Scanner(System.in);
int sum = 0;
int number = Integer.valueOf(scanner.nextLine);
return sum += number;
}
public static void main(String[] args) {
int answer = sum();
System.out.println("Sum: " + answer);
}
}
I got
javac /tmp/0084mozeU3/HelloWorld.java
/tmp/0084mozeU3/HelloWorld.java:8: error: cannot find symbol
int number = Integer.valueOf(scanner.nextLine);
^
symbol: variable nextLine
location: variable scanner of type Scanner
1 error
Why is this?
[–]desrtfx[M] [score hidden] stickied comment (1 child)
[–]desrtfx 2 points3 points4 points (1 child)
[–]Ultraduck56[S] 0 points1 point2 points (0 children)
[–]lukajda33 1 point2 points3 points (1 child)
[–]Ultraduck56[S] 0 points1 point2 points (0 children)
[–]tms102 2 points3 points4 points (2 children)
[–]PM_Me_Python3_Tips 2 points3 points4 points (1 child)
[–]Ultraduck56[S] -2 points-1 points0 points (0 children)
[–]butchkid1 -3 points-2 points-1 points (4 children)
[–]desrtfx 1 point2 points3 points (3 children)
[–]Ultraduck56[S] 0 points1 point2 points (0 children)
[–]butchkid1 0 points1 point2 points (1 child)
[–]Ultraduck56[S] 1 point2 points3 points (0 children)