File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ class Student
3+ {
4+ public String name ;
5+ public float percentage ;
6+ Student (String name , float percentage )
7+ {
8+ this .name =name ;
9+ this .percentage =percentage ;
10+ }
11+ }
12+ class Test extends Student
13+ {
14+ Test (String name , float percentage )
15+ {
16+ super (name , percentage );
17+ }
18+ public static void display (Test [] obj )
19+ {
20+ for (int i =0 ;i <obj .length ;i ++)
21+ {
22+ for (int j =i +1 ;j <obj .length ;j ++)
23+ {
24+ if (obj [i ].percentage <obj [j ].percentage )
25+ {
26+ Test t = obj [i ];
27+ obj [i ]=obj [j ];
28+ obj [j ]=t ;
29+ }
30+ }
31+ }
32+ System .out .println (obj [0 ].name + " " + obj [0 ].percentage );
33+ }
34+ }
35+ class Main
36+ {
37+ public static void main (String args [])
38+ {
39+ Scanner sc = new Scanner (System .in );
40+ System .out .println ("Enter number of students appeared in the test" );
41+ int size = sc .nextInt ();
42+ Test obj [] = new Test [size ];
43+ for (int i =0 ;i <obj .length ;i ++)
44+ {
45+ System .out .println ("Enter the details" );
46+ obj [i ]=new Test (sc .next (), sc .nextFloat ());
47+ }
48+ Test .display (obj );
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments