Skip to content

Instantly share code, notes, and snippets.

@lrlucena
Last active September 28, 2015 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrlucena/27bad7754813f12429dd to your computer and use it in GitHub Desktop.
Save lrlucena/27bad7754813f12429dd to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Ranking {
static class Participante {
public final String nome;
public final int nota;
public Participante(String nome, int nota) {
this.nome = nome;
this.nota = nota;
}
public String dados() {
return nome + " - " + nota;
}
}
public static void main(String... args) {
final Scanner sc = new Scanner(System.in);
final List<Participante> pessoas = new ArrayList(200);
for (int i = 0; i <= 200; i++) {
System.out.println("Digite o nome: ");
final String nome = sc.nextLine();
System.out.println("Digite a nota: ");
final int nota = sc.nextInt();
pessoas.add(new Participante(nome, nota));
}
Collections.sort(pessoas, new Comparator<Participante>() {
@Override
public int compare(Participante o1, Participante o2) {
return o1.nota - o2.nota;
}
});
for (Participante p : pessoas) {
if (p.nota > 70) {
System.out.println(p.dados());
}
}
}
}
case class Participante(nome: String, nota: Int) {
override def toString = nome + " - " + nota
}
object Rank extends App {
val pessoas =
for (i <- 1 to 200) yield {
print(s"Digite o nome do ${i}º Candidato: ")
val nome = readLine
print("Digite a nota: ")
val nota = readInt
Participante(nome, nota)
}
pessoas.filter(_.nota > 70)
.sortBy(_.nota)
.reverse
.foreach(println)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment