Write a program in java to accept the marks of 10 subjects and display the highest and lowest marks obtained using array.
Answers
Answered by
2
import java. util . * ;
class Subject
{
static void main ()
{
Scanner sc = new Scanner(System.in) ;
double marks[] = new double[10] ;
System.out.println (" Enter the marks of 10 subjects : ") ;
for ( int i=0 ; i < marks. legth ; i ++ )
{
System.out.println ( " Enter the marks : " + ( i + 1 )) ;
marks [i] = sc. nextDouble() ;
}
double max = marks[0] , min = marks[0] ;
for ( int i= 0 ; i< marks. length ; i++ )
{
if ( marks[i] > max)
{
max = marks [i] ;
}
if ( marks[i] < min)
{
min = marks[i] ;
}
}
System. out. println (" Highest marks : " + max + " Lowest marks : " + min ) ;
}
}
_____________________________
- Given in the attachment is the output of the above program
Attachments:
Similar questions