The teacher asked for the following exercise:
"Write a program that gets three scores (integers), sorts those scores using if statements and writes the three in ascending order on the screen. "
I tried to do it my way alone but I ended up getting wrapped up for almost 30 minutes lost in the middle of so many if's and else's and went to see the resolution that the teacher made available, but I can not understand it. The resolution is as follows: / p>
System . out . println("Indique a 1ª pontuação:");
int pontuacao1=scanner.nextInt();
System . out . println("Indique a 2ª pontuação:");
int pontuacao2 = scanner.nextInt();
System . out . println("Indique a 3ª pontuação:");
int pontuacao3 = scanner.nextInt();
if (pontuacao2 < pontuacao1)
{
int valor = pontuacao1;
pontuacao1 = pontuacao2;
pontuacao2 = valor;
}
if (pontuacao3 < pontuacao2)
{
int valor = pontuacao2;
pontuacao2 = pontuacao3;
pontuacao3 = valor;
if (pontuacao2 < pontuacao1)
{
int valor2 = pontuacao1;
pontuacao1 = pontuacao2;
pontuacao2 = valor;
}
}
System.out.print(pontuacao1 + ", " + pontuacao2 + ", " + pontuacao3);
The first part of input values I realize but from the if not. Can anyone explain?