import javax.swing.JOptionPane;
public class ejemp05_for{
public static void main(String args[]){
int i;
i = Integer.parseInt(JOptionPane.showInputDialog("¿Cual tabla de multiplicar del 1 al 12 quieres que te imprima?" ));
switch (i) {
case 1:
for (i = 0; i < 12 ; i++){
System.out.printf("\n1 x "+ i +" = "+(i*1));
}
break;
case 2:
for (i = 0; i < 12 ; i++){
System.out.printf("\n2 x "+ i +" = "+(i*2));
}
break;
case 3:
for (i = 0; i < 12 ; i++){
System.out.printf("\n3 x "+ i +" = "+(i*3));
}
break;
case 4:
for (i = 0; i < 12 ; i++){
System.out.printf("\n4 x "+ i +" = "+(i*4));
}
break;
case 5:
for (i = 0; i < 12 ; i++){
System.out.printf("\n5 x "+ i +" = "+(i*5));
}
break;
case 6:
for (i = 0; i < 12 ; i++){
System.out.printf("\n6 x "+ i +" = "+(i*6));
}
break;
case 7:
for (i = 0; i < 12 ; i++){
System.out.printf("\n7 x "+ i +" = "+(i*7));
}
break;
case 8:
for (i = 0; i < 12 ; i++){
System.out.printf("\n8 x "+ i +" = "+(i*8));
}
break;
case 9:
for (i = 0; i < 12 ; i++){
System.out.printf("\n9 x "+ i +" = "+(i*9));
}
break;
case 10:
for (i = 0; i < 12 ; i++){
System.out.printf("\n10 x "+ i +" = "+(i*10));
}
break;
case 11:
for (i =0; i < 12 ; i++){
System.out.printf("\n11 x "+ i +" = "+(i*11));
}
break;
case 12:
for (i =0; i < 12 ; i++){
System.out.printf("\n12 x "+ i +" = "+(i*12));
}
break;
default:
JOptionPane.showMessageDialog(null, "La opcion no existe:");
break;
}
}
}
No hay comentarios:
Publicar un comentario