Ayuden a esta pobre mujer!!!
Publicado por Fernanda (1 intervención) el 11/10/2012 08:38:41
Estoy estudiando actualmente algo de Estructuras condicionales anidadas, Mi programa consiste básicamente en ingresar 4 valores y de esos 4 valores el programa seleccionara el mayor de ellos. Ya lo hice pero solo funciona con algunas combinaciones de numeros, alguien me puede decir el error que estoy cometiendo?
import java.util.Scanner;
public class Prueba {
public static void main(String[] ar){
Scanner teclado=new Scanner(System.in);
int n1,n2,n3,n4;
System.out.print("Ingrese primer valor:");
n1=teclado.nextInt();
System.out.print("Ingrese segundo valor:");
n2=teclado.nextInt();
System.out.print("Ingrese tercer valor:");
n3=teclado.nextInt();
System.out.print("ingrese cuarto valor:");
n4=teclado.nextInt();
if (n1>n2){
if (n1>n3){
if (n1>n4){
System.out.print("El primer valor");
} else {
System.out.print("El cuarto valor");
}
}else{
// if (n3>n2){
if (n3>n4){
System.out.print("El tercer valor");
} else {
System.out.print("El cuarto valor");
}
// }
}
} else {
if (n2>n3){
if (n2>n4){
System.out.print("El segundo valor");
}else{
System.out.print("El cuarto valor");
}
}
}
}
}
import java.util.Scanner;
public class Prueba {
public static void main(String[] ar){
Scanner teclado=new Scanner(System.in);
int n1,n2,n3,n4;
System.out.print("Ingrese primer valor:");
n1=teclado.nextInt();
System.out.print("Ingrese segundo valor:");
n2=teclado.nextInt();
System.out.print("Ingrese tercer valor:");
n3=teclado.nextInt();
System.out.print("ingrese cuarto valor:");
n4=teclado.nextInt();
if (n1>n2){
if (n1>n3){
if (n1>n4){
System.out.print("El primer valor");
} else {
System.out.print("El cuarto valor");
}
}else{
// if (n3>n2){
if (n3>n4){
System.out.print("El tercer valor");
} else {
System.out.print("El cuarto valor");
}
// }
}
} else {
if (n2>n3){
if (n2>n4){
System.out.print("El segundo valor");
}else{
System.out.print("El cuarto valor");
}
}
}
}
}
Valora esta pregunta


0