Why is it showing me error while assigning nextIn() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it showing me error while assigning nextIn()

public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please enter a number"); int number =s.nextInt(); int sum =0; while (number!= -1) { sum +=number; System.out.println("Please give a number"); number=s.nextInt();} System.out.println("Sum of output is : " +sum); } }

26th Oct 2022, 9:10 PM
Rakan Ezzedin
1 Answer
+ 1
You use "s.nextInt" but the scanner is declared as "scan" then you would use "scan.nextInt"
26th Oct 2022, 9:27 PM
KrOW
KrOW - avatar