1. Write a program to accept marks of 20 students in Computer Application subject and display the name of the student who has scored the highest marks.
Answers
Answered by
4
Question:-
- Write a program to accept marks of 20 students in Computer Application subject and display the name of the student who has scored the highest marks.
Program:-
I am writing in Java.
First method(using arrays)
import java.util.*;
class Marks
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter marks of 20 students. ");
int a[]=new int[20];
for(int i=0;i<20;i++)
a[i]=sc.nextInt();
int max=a[0];
for(int i=0;i<20;i++)
{
if(a[i]>max)
max=a[i];
}
System.out.println("Largest number is: "+max);
}
}
Another method(without using arrays)
import java.util.*;
class Marks
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter marks of 20 students. ");
int max=0;
for(int i=0;i<20;i++)
{
int a=sc.nextInt();
if(a>max)
max=a;
}
System.out.println("Largest number is: "+max);
}
}
Similar questions