Answer to Question #255774 in Java | JSP | JSF for Amadix

Question #255774

Write a java program that accepts given n number of marks for a PRG510S test, and stores them into an array named marks. After all marks have been entered your program should accomplish the following: 

[- to be provided by user input]

a)   Find and display the highest mark

b)   Find and display the lowest mark

c)    Compute and display the average mark

(Above tasks (a, b, and c should be accomplished using only one loop)


1
Expert's answer
2021-10-24T05:54:40-0400
import java.util.Scanner;
public class Main
{
 public static void main(String[] args) {
 Scanner input=new Scanner(System.in);
 int number;
 System.out.print("Enter numbers of marks:");
 number=input.nextInt();
 int [] marks = new int [number];
 System.out.print("Enter "+number+" marks:");
 for(int x=0;x<number;x++){
 marks[x]=input.nextInt();
 }
 int High=marks[0];
 int low=marks[0];
 int Ave;
 int add=0;
 for(int x=0;x<number;x++){
 add+=marks[x];
 if(marks[x]>High){
 High=marks[x];
 }
 if(marks[x]<low){
 low=marks[x];
 }
 }
 Ave=add/number;
 
 System.out.println("Highest Mark = "+High+"%");
 System.out.println("Lowest Mark = "+low+"%");
 System.out.println("Average = "+Ave+"%");
 }
}

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