Answer to Question #8764 in Java | JSP | JSF for wilfred

Question #8764
input the marks for each student and store in an array called supp.the input must be validated before being stored :input are 15 27 38 2 98 42 87 92 99 13 5 72 67 2 1
my qestion is how do i determine and display the highest and lowest mark
1
Expert's answer
2012-04-28T09:45:51-0400
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
& Scanner in = new Scanner(System.in);
& int n;
& System.out.print("Enter number of students: ");
& n = in.nextInt();
& int []supp = new int[n];
& System.out.print("Enter "+n+" marks: ");
& for (int i=0;i<n;i++){
& double temp;
& temp=in.nextDouble();
& if ((temp%1!=0)||(temp<0)){
& System.out.println("Mark error "+temp+" try again!");
& i--;
& }
& else supp[i]=(int)temp;
& }
& int max=0;
& int min=Integer.MAX_VALUE;
& for (int i=0;i<n;i++){
& if (supp[i]>max)
& max=supp[i];
& if (supp[i]<min)
& min=supp[i];
& }
& System.out.println("The lowest mark: "+min);
& System.out.println("The higest mark: "+max);
}

}

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
APPROVED BY CLIENTS