-2
An algorithm that reads 3 integer values, not repeated, and shows in descending order. But it is showing 3 results, and should only be 1
package praticando;
import java.util.Scanner;
public class Exercicio2 {
public static void main(String[] args) {
Scanner valor = new Scanner(System.in);
System.out.println("Digite o primeiro número: ");
int A = valor.nextInt();
System.out.println("Digite o segundo número: ");
int B = valor.nextInt();
System.out.println("Digite o terceiro número: ");
int C = valor.nextInt();
if (A == B || B == C || A== C) {
System.out.println("Existem números repetidos!");
}
if (A > B & A > C) { //A é o maior
} if(B > C){
System.out.println(+A+" -> "+B+" -> "+C);
} else {
System.out.println(+A+" -> "+C+" -> "+B);
}
if (B > A & B > C) { //B é o maior
} if(A > C){
System.out.println(+B+" -> "+A+" -> "+C);
} else {
System.out.println(+B+" -> "+C+" -> "+A);
}
if (C > A & C > B) { //C é o maior
} if(A > B){
System.out.println(+C+" -> "+A+" -> "+B);
}else{
System.out.println(+C+" -> "+B+" -> "+A);
}
}
}
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero