In: Computer Science
Could you give some sample Java code of creating a program where users are prompt to determine how many exams they have taken then it is prompt that they have to enter their test scores and gives the sum of all their test scores? You should have to use looping
import java.util.*;
public class Main
{
public static void main(String[] args) {
int n,i,s=0;
Scanner inp=new Scanner(System.in);
System.out.println("how many exams
you have taken?");
n=inp.nextInt();//read number of
exams
System.out.println("Enter test
scores");
for(i=0;i<n;i++){
s+=inp.nextInt();//read test score
and add it to s
}
System.out.println("Sum is
"+s);//print the sum value
}
}
Screenshots:
The screenshots are attached below for reference.
Please follow them for proper output.
Please upvote my answer .
Thank you.