import javax.swing.JOptionPane;
public class ejemp06_fact{
public static void main (String args[]){
int i = 1, acu = 1, num = 0, seguir = 0;
String Numero;
while(seguir == 0){//inicio while validar numero positivo
Numero = JOptionPane.showInputDialog("Que numero factorial desea calcular? ");
num = Integer.parseInt( Numero );
if(num <= 0){
JOptionPane.showMessageDialog(null,"Error,Ingrese un numero positivo",
"Error", JOptionPane.PLAIN_MESSAGE);
}
else{
seguir = 1;
}
}//fin while validar numero positivo
while(i <= num){
acu = acu * i;
i++;
}
JOptionPane.showMessageDialog(null, "" + num + "! = " + acu, "Resultado",
JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
domingo, 15 de mayo de 2011
TABLA DE MULTIPLICACION CON FOR
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;
}
}
}
INGRESAR LA CANTIDAD DE NUMEROS POSITIVOS Y NEGATIVOS UTILIZANDO WHILE
import javax.swing.JOptionPane;
public class ejemp04_while{
public static void main(String args[]){
String entrada=JOptionPane.showInputDialog("ingrese cantidad de numeros negativos");
int neg= Integer.parseInt(entrada);
String cant=JOptionPane.showInputDialog("ingrese cantidad de numeros positivos");
int pos= Integer.parseInt(cant);
int n;
int i=1;
while(i<=pos ){
String nume = JOptionPane.showInputDialog("ingrese el num"+i+":");
int num =Integer.parseInt(nume);
if (num > 0){
pos=pos+1;
}
else
if (num < 0){
neg=neg+1;
}
else
{
JOptionPane.showMessageDialog (null,"el numero ingresado es cero");
}
i=i+1;
{
JOptionPane.showMessageDialog (null,"total de numeros negativos:" + neg);
JOptionPane.showMessageDialog (null, "total de numeros positivos:" + pos);
}
}
}
}
public class ejemp04_while{
public static void main(String args[]){
String entrada=JOptionPane.showInputDialog("ingrese cantidad de numeros negativos");
int neg= Integer.parseInt(entrada);
String cant=JOptionPane.showInputDialog("ingrese cantidad de numeros positivos");
int pos= Integer.parseInt(cant);
int n;
int i=1;
while(i<=pos ){
String nume = JOptionPane.showInputDialog("ingrese el num"+i+":");
int num =Integer.parseInt(nume);
if (num > 0){
pos=pos+1;
}
else
if (num < 0){
neg=neg+1;
}
else
{
JOptionPane.showMessageDialog (null,"el numero ingresado es cero");
}
i=i+1;
{
JOptionPane.showMessageDialog (null,"total de numeros negativos:" + neg);
JOptionPane.showMessageDialog (null, "total de numeros positivos:" + pos);
}
}
}
}
TABLA DE MULTIPLICACION CON WHILE
import javax.swing.JOptionPane;
public class ejemp03_while{
public static void main(String args[]){
String entrada=JOptionPane.showInputDialog("ingrese numero");
int num=Integer.parseInt(entrada);
int i;
i=0;
while (i<=12){
JOptionPane.showMessageDialog(null,num+"*"+i+"="+(num*i));
i=i+1;
}
}
}
public class ejemp03_while{
public static void main(String args[]){
String entrada=JOptionPane.showInputDialog("ingrese numero");
int num=Integer.parseInt(entrada);
int i;
i=0;
while (i<=12){
JOptionPane.showMessageDialog(null,num+"*"+i+"="+(num*i));
i=i+1;
}
}
}
mostrar la cantidad de numeros determinados
import javax.swing.JOptionPane;
public class ejemp02{
public static void main(String args[]){
String entrada= JOptionPane.showInputDialog("ingrese numero");
int mun=Integer.parseInt(entrada);
int i;
i=1;
while(i<=mun)
{
JOptionPane.showMessageDialog(null,"el num es"+i);
i=i+1;
}
}
}
public class ejemp02{
public static void main(String args[]){
String entrada= JOptionPane.showInputDialog("ingrese numero");
int mun=Integer.parseInt(entrada);
int i;
i=1;
while(i<=mun)
{
JOptionPane.showMessageDialog(null,"el num es"+i);
i=i+1;
}
}
}
convertir soles a dolares y euros
import javax.swing.JOptionPane;
public class dolares_euros{
public static void main (String args[]){
String cant = JOptionPane.showInputDialog("ingrese cantidad de soles ");
double soles= Double.parseDouble(cant);
double dolares = soles/2.80;
double euros = soles/3.50;
JOptionPane.showMessageDialog(null,"la cantidad de dolares es: "+ dolares);
JOptionPane.showMessageDialog(null,"la cantidad de euros es: "+ euros);
}
}
public class dolares_euros{
public static void main (String args[]){
String cant = JOptionPane.showInputDialog("ingrese cantidad de soles ");
double soles= Double.parseDouble(cant);
double dolares = soles/2.80;
double euros = soles/3.50;
JOptionPane.showMessageDialog(null,"la cantidad de dolares es: "+ dolares);
JOptionPane.showMessageDialog(null,"la cantidad de euros es: "+ euros);
}
}
MOSTRAR LOS DIEZ PRIMEROS NÙMEROS NATURALES
import javax.swing.JOptionPane;public class ejemp01{
public static void main (String args[]){
String hola=JOptionPane.showInputDialog("mostrar diez primeros numeros");
Double mun= Double.parseDouble(hola);
int i;
i=1;
while(i<=10){
{
JOptionPane.showMessageDialog(null,"el mun es" +i);
i=i+1;
}
}
}
Suscribirse a:
Entradas (Atom)




