I need to sort three numbers and I can not use for
or vectors.
I know it's easy but I can not do it. My problem is: I can not save the highest value.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int menor = 0;
int maior = 0;
System.out.println(" Tres números:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if((a < b) && (a < c))
menor = a;
else if((b < a)&&(b < c))
menor = b;
else if((c < a)&&(c < b))
menor = c;
System.out.println(" Maior: " + maior + " Menor:" + menor);
}
Oops, I think I got it resolved.
if((a < b) && (a < c))
menor = a;
else if((b < a)&&(b < c))
menor = b;
else if((c < a)&&(c < b))
menor = c;
if((a > b) && (a > c))
maior = a;
else if((b > a)&&(b > c))
maior = b;
else if((c > a)&&(c > b))
maior = c;
System.out.println(" Maior: " + maior + " Menor:" + menor);
}