4
I need to sort three numbers I can’t use for
and neither vectors.
I know it’s easy but I can’t do it. My problem is, I can’t keep 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 right.
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);
}
switch case can?
– user28595
Yeah. But I think I figured it out, look if it’s right?
– Aline