-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
50 lines (50 loc) · 972 Bytes
/
Main.java
File metadata and controls
50 lines (50 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
class Student
{
public String name;
public float percentage;
Student(String name, float percentage)
{
this.name=name;
this.percentage=percentage;
}
}
class Test extends Student
{
Test(String name, float percentage)
{
super(name, percentage);
}
public static void display(Test[] obj)
{
for(int i=0;i<obj.length;i++)
{
for(int j=i+1;j<obj.length;j++)
{
if(obj[i].percentage<obj[j].percentage)
{
Test t = obj[i];
obj[i]=obj[j];
obj[j]=t;
}
}
}
System.out.println(obj[0].name + " " + obj[0].percentage);
}
}
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of students appeared in the test");
int size = sc.nextInt();
Test obj[] = new Test[size];
for(int i=0;i<obj.length;i++)
{
System.out.println("Enter the details");
obj[i]=new Test(sc.next(), sc.nextFloat());
}
Test.display(obj);
}
}