Demo entry 6726205

java

   

Submitted by anonymous on Mar 27, 2018 at 17:40
Language: Java. Code size: 796 Bytes.

import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;


public class Main{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		Student[] stu = new Student[8];
		for(int i = 0; i < 8;i++) {
			stu[i] = new Student(cin.next(),cin.nextInt());
		}
		Arrays.sort(stu,new Student());
		for(int i = 0; i < 8;i++) {
			System.out.println(stu[i]);
		}	
	}
}

class Student implements Comparator<Student>{
	public String Name;
	public int Grade;
	
	public Student(String name, int grade) {
		Name = name;
		Grade = grade;
	}
	public Student() {}
	@Override
	public String toString() {
		return Name + " " + Grade;
	}
	@Override
	public int compare(Student o1, Student o2) {
		// TODO Auto-generated method stub
		return o2.Grade - o1.Grade;
	}
	
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).