Tonterita del auto
public class auto {
public static void main (String [] args) {
int max = 100;
int auto = 120;
if (auto > max) {
System.out.println("El auto va muy rápido");
} else {
System.out.println("El auto va muy lento");
}
}
}
if
public class oper_if {
public static void main (String [] args) {
int x = 2;
int y = 4;
char letra = '*';
if (letra == '+') {
System.out.println("x + y = " + (x+y));
} else {
if (letra == '-') {
System.out.println("x - y = " + (x-y));
} else {
if (letra == '*') {
System.out.println("x * y = " + (x*y));
} else {
if (letra == '/') {
System.out.println("x / y = " + (x/y));
}
}
}
} // fin del primer if
}
}
switch
public class oper_switch {
public static void main (String [] args) {
int x = 2;
int y = 4;
char letra = '*';
switch (letra) {
case '+':
System.out.println("x + y = "+ (x+y));
break;
case '-':
System.out.println("x - y = "+ (x-y));
break;
case '*':
System.out.println("x * y = "+ (x*y));
break;
case '/':
System.out.println("x / y = "+ (x/y));
break;
}
}
}
Salu2
Victor Alvarez
No hay comentarios:
Publicar un comentario