Answer to Question #41345 in Java | JSP | JSF for solomon

Question #41345
accept marks of five students and then displays their average. The program shoud not accept mark which is less than 0 and mark greater than 100. use array concept.
1
Expert's answer
2014-05-15T10:40:05-0400
import java.util.Scanner;

public class Students {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double[] arrayOfStudents = newdouble[5];
double sum = 0;
for (int i = 0; i <arrayOfStudents.length; i++) {
System.out.print("Input markfor " + (i + 1) + " student: ");
int mark =Integer.parseInt(input.nextLine());
if (mark >= 0 && mark<= 100) {
arrayOfStudents[i] = mark;
sum += mark;
} else {
i--;
System.out.println("Badmark inputed. Try again");
}
}
double average = sum /arrayOfStudents.length;
System.out.println("Average:" + average);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS