A one dimensional double type array named studentScores has

A one dimensional double type array, named studentScores, has N elements. Write a Java program that reads double type students\' score values from the keyboard and assigns these values to all the N elements of this array. The program should then find and display the maximum score value stored in the array (your program should display some message, which lets the user know that the data value displayed is the maximum score value).

Solution

import java.util.Scanner;

public class MaxScore {
  


   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int N;
       Scanner sc=new Scanner(System.in);
       System.out.println(\"Enter N for no of students \");
       N=sc.nextInt();
       double studentScores[]=new double[N];
      
       for(int i=0;i<N;i++)
       {
           System.out.println(\"Enter score for student \");//accept data from user
           studentScores[i]=sc.nextDouble();
       }
      
       double max=-9999;
       for(int i=0;i<N;i++)//loop to find max score
       {
          
           if(max<studentScores[i]) //if max is lessthan current element then update max
           {
               max=studentScores[i];
           }
       }
      

       System.out.println(\"Maximum score is \"+max);//print result
   }

}

==========================================

Enter N for no of students
3
Enter score for student
3
Enter score for student
4
Enter score for student
5
Maximum score is 5.0

 A one dimensional double type array, named studentScores, has N elements. Write a Java program that reads double type students\' score values from the keyboard

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site