+ 2
I don't know why I am Getting error in this? Error is " you must declare main class" and the variable is not defined.
Kindly tell what is wrong in this??? import java.util.Scanner; class Ans{ public static void main(String[] args){ Scanner s = new Scanner(System.in); int sum = 0; for(int i = 0; i<10;i++){ System.out.println("Enter a number"); int x= s.nextInt(); sum = sum+x; } System.out.println("Sum is "+sum); } }
8 Respuestas
+ 1
Did you give 10 numbers as input, each in different lines? I tried to run it with 10 numbers and it worked.
+ 1
I have used the loop na then why should I input th seperately?
Also nothing happened even when I wrote public before class🥺🥺
+ 1
Ya I have seen the link...but my code is somewhat write na bcz instead of 10 if it was to input 100 integers then surely we would have used loop only na
0
~ swim ~
Will there be a problem as the class 'Ans' isn't specified public?
0
Then what is the correct code?
Can anyone help