3
The teacher asked for the next exercise:
"Write a program that receives three scores (integer numbers); sort these scores using if instructions and write the three in ascending order on the screen."
I tried to do it my own way but I ended up curled up for almost 30 minutes lost in the middle of so many if’s and E-e-s and went to see the resolution that the teacher made available, but I can’t understand it. The resolution is as follows::
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 understand but from the if is not. Someone can explain?