Ejemplo 1: declaraciones else if de Java
System.out.println("How many sattelites does JUPITER have ??");
C = scan.nextInt();
if (C == 79)
{
System.out.println("Congrats ! You got the Third Question Right :)");
points = points + 1;
}
else if (C != 79)
{
System.out.println("Sorry but your answer is wrong :(");
}
Ejemplo 2: instrucción else java
int x = 3;
if (x == 3) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
Ejemplo 3: else if java
else if statement is used to specify new condition if first condition is false.
Syntax:
if(condition1)
{
// execute if condition1 is true
}
else if (condition2)
{
// execute if condition2 is true
}
else if (condition3)
{
// execute if condition3 is true
}
else
{
// execute if conditions 1, 2 and 3 becomes false
}
Ejemplo 4: instrucción if anidada en java
if(something){
if(somethingElse){
doSomething();
}//else (if) block possible here
}//else (if) block possible here
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)