-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrade2.java
More file actions
94 lines (88 loc) · 2.51 KB
/
Grade2.java
File metadata and controls
94 lines (88 loc) · 2.51 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Program: Generate Student Rank List Based on Total Marks
// Topic: 2D Arrays, Sorting, and Loops
// Description: Accepts names and marks of 2 students in 3 subjects, calculates total marks for each,
// and sorts them in descending order to display a ranked list. Demonstrates nested loops and array swapping for sorting logic.
package Array2D;
import java.util.*;
/**
*
* @author Samim
*/
public class Grade2
{
public static String name[]=new String[2];
public static int total[]=new int[2];
public static void Input()
{
Scanner sc=new Scanner(System.in);
int ar[][]=new int[2][3];
for(int i=0;i<2;i++)
{
System.out.println("Enter Name Of Students :");
name[i]=sc.next();
for(int j=0;j<3;j++)
{
System.out.println("Enter The Marks "+(j+1));
ar[i][j]=sc.nextInt();
total[i]+=ar[i][j];
}
System.out.println(total[i]);
}
}
// public static void Grade()
// {
// char grade[]=new char[2];
// double avg;
// for(int i=0;i<3;i++)
// {
// //avg=total[i]/3;
// if(avg<45.0)
// {
// grade[i]='D';
// }
// else if(avg <60.0)
// {
// grade[i]='C';
// }
// else if(avg <75.0)
// {
// grade[i]='B';
// }
// else
// {
// grade[i]='A';
// }
// }
// }
public static void RankList()
{
System.out.println("Rank List :");
for(int i=0;i<3;i++)
{
for(int j=0;j<3-i-1;j++)
{
if(total[j+1]>total[j])
{
int temp=total[j+1];
total[j+1]=total[j];
total[j]=temp;
String temp2=name[j+1];
name[j+1]=name[j];
name[j]=temp2;
}
}
}
for(int i=0;i<3;i++)
{
System.out.println((i+1)+" rank : "+name[i]);
System.out.println("Total Marks :"+total[i]);
System.out.println();
}
}
public static void main(String args[])
{
Input();
//Grade();
RankList();
}
}