0
No lo puedo compilar por favor
import java.util.Scanner; public class ejercicio23 { public static void main(String[] args) { Scanner captura = new Scanner(System.in); int edad1; int edad2; int difereciaEdad; System.out.println("Ingrese edad1"); edad1 = captura.nextInt(); System.out.println("Ingrese edad2"); edad2 = captura.nextInt(); if ( edad1 > edad2 ); { int resta; resta = edad1 - edad2; difereciaEdad = resta; System.out.println(" Es el hermano mayor" + resta); else { int resta; resta = edad2 - edad1; difereciaEdad = resta; } System.out.println(" es el hermano mayor" + resta); } } }
4 Answers
+ 4
Here you go, I put some comments to point out the issues, hope you understand;
import java.util.Scanner;
public class ejercicio23
{
public static void main(String[] args)
{
Scanner captura = new Scanner(System.in);
int edad1;
int edad2;
int difereciaEdad;
System.out.println("Ingrese edad1");
edad1 = captura.nextInt();
System.out.println("Ingrese edad2");
edad2 = captura.nextInt();
if (edad1 > edad2) // <- don't put ; at end of this line
{
int resta;
resta = edad1 - edad2;
difereciaEdad = resta;
System.out.println("Es el hermano mayor " + resta);
} // <- don't forget end of block
else
{
int resta;
resta = edad2 - edad1;
difereciaEdad = resta;
System.out.println("Es el hermano mayor " + resta); // <- resta is local, print resta in here, resta is unknown outside this block
}
}
}
+ 2
De nada ... You're welcome : )
+ 1
Gracias..
0
Ayúdenme a corregirlo