plz help me solve this program
Answers
1.You mean inputs 10 numbers and then print the sum. Well let's go coding...:
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner input = new Scanner(system.in);
int sum = 0;
for (int i = 0; i < 10; i += 1){
sum += input.nextInt();
}
System.out.println("The total sum is: " + sum );
}
}
First line, importing input scanner: slow in taking input but simple one. Second and third line, class and main method description. Fourth line, creating instance of scanner(getting ready to take the input). Fifth line, initialized a variable to zero, so that we could sum up all the upcoming integers into this variable. Sixth line, running a loop ten times. Seventh line, taking input and adding it to the sum variable. Ninth line finally printing sum to the console.
You're done! :)