viernes, 11 de junio de 2010

CICLO DO - WHILE (PARES)

import javax.swing.JOptionPane;
public class dowhilepares1
{
public static void main (String args [ ])
{

// DECLARACION DE VARIABLES
int i;
String name;

// ENTRADA DE DATOS
name = JOptionPane.showInputDialog (" Cómo te llamas ?.....");


// CICLO DO - WHILE
String cad="";
i = 2;

do {

cad= cad + "\n" +i;
i = i + 2;
}

while (i <= 10);


// SALIDA DE DATOS
JOptionPane.showMessageDialog
(null,"LOS NUMEROS PARES SON: \n" + cad);

System.exit(0);
}
}

martes, 8 de junio de 2010

OPERACIONES ARITMETICAS VERSION 2

import javax.swing.JOptionPane;
public class aritmetica2
{
public static void main (String args [ ])
{

// DECLARACION DE VARIABLES
float num1, num2, suma, resta, multi, division;
String entrada, name;

// ENTRADA DE DATOS
name = JOptionPane.showInputDialog (" Cómo te llamas ?.....");

entrada = JOptionPane.showInputDialog ("Teclea el primer valor ");
num1 = Float.parseFloat(entrada);
entrada = JOptionPane.showInputDialog ("Teclea el segundo valor ");
num2 = Float.parseFloat(entrada);

// OPERACIONES ARITMETICAS
suma = num1 + num2;
resta = num1- num2;
multi = num1 * num2;
division = num1 / num2;

// SALIDA DE DATOS
JOptionPane.showMessageDialog
(null,"LOS RESULTADOS DE LAS OPERACIONES ARITMETICAS SON: \n \n La suma de " +num1 + " + " +num2 +" = " + String.format("%.2f",suma) +"\n La resta de " +num1 + " - " +num2 +" = " + String.format("%.2f",resta)+"\n La multiplicacion de " +num1 +" * " +num2 +" = " +multi+ String.format("%.2f",multi) +"\n La división de " +num1 +" / " +num2 +" = " + String.format("%.2f",division) +"\n \n Realizadas por " +name);
System.exit(0);
}
}

martes, 1 de junio de 2010

CICLO WHILE (PARES)

import javax.swing.JOptionPane;
public class pareswhile
{
public static void main (String args [ ])
{

// DECLARACION DE VARIABLES
int n, i;
String entrada, name;

// ENTRADA DE DATOS
name = JOptionPane.showInputDialog (" Cómo te llamas ?.....");

// CICLO WHILE
String cad="";

i = 2;
while (i <= 30) {
cad= cad + "\n" +i;

i = i + 2;
}

// SALIDA DE DATOS
JOptionPane.showMessageDialog
(null,"LOS NUMEROS PARES SON: \n" + cad);

System.exit(0);
}
}

PROGRAMA MESES (FOR)

import javax.swing.JOptionPane;
public class meses
{
public static void main (String args [ ])
{

// DECLARACION DE VARIABLES
int i;
String entrada, name, mes;

// ENTRADA DE DATOS
name = JOptionPane.showInputDialog (" Cómo te llamas ?.....");


// CICLO FOR
String cad=" ";
for (i = 1 ; i <= 12; i++) {
mes = JOptionPane.showInputDialog (" Mes No. " +i);
cad= cad + "\n" +mes;

}

// SALIDA DE DATOS
JOptionPane.showMessageDialog
(null,"LOS SON: \n" +cad);

System.exit(0);
}
}