Sie sind auf Seite 1von 7

INSTITUTO TECNOLGICO DE MATEHUALA

RESUMEN, EJERCICIOS Y PROGRAMAS


Elabor: Conde Olivares Juan Armando Castillo Hernndez ngel Arturo Barbosa Rodrguez Pedro Alberto Sauceda Olvera Juan Jos

Materia:

Algoritmos y lenguajes de Programacin

Docente: Ing. Martn Luis Ledezma Hernndez Carrera: Grupo: Ingeniera Industrial Cuarto semestre A

Unidad 5: Estructuras Selectivas Semestre: Enero-Junio 2011

Matehuala, S.L.P.

Junio 2011

PROBLEMA 1 Identificar de dos nmeros enteros diferentes cual es mayor y cual menor Programa fuente importjavax.swing.JOptionPa ne; public class Condicional { public static void main( String args[] ) { StringprimerNumero; StringsegundoNumer o; String resultado; int numero1; int numero2; primerNumero = JOptionPane.showInputDialog(" Escriba el primer nmero: "); segundoNumero = JOptionPane.showInputDialog(" Escriba el segundo nmero "); numero1 = Integer.parseInt(primerNumero); numero2 = Integer.parseInt(segundoNumero); resultado = " "; if ( numero1 > numero2 ) resultado = resultado + numero1 + " es mayor que " +numero2; else { if (numero1 == numero2) resultado = resultado + numero1 + " es igual que " +numero2; else resultado = resultado + numero2 + " es mayor que " +numero1; } JOptionPane.showMessageDialog(null, resultado, " Resultados ", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }

Resultados.

PROBLEMA 2 Identificar si un nmero entero positivo es par impar Programa fuente importjavax.swing.JOptionPa ne; public class ParImpar { public static void main(String[] args) { String entrada = JOptionPane.showInputDialog(null, "Introduce un nmero: "); int numero = Integer.parseInt(entrada); if (numero % 2 == 0) { JOptionPane.showMessageDialog(null, "El numero " + numero + " es par"); } else { JOptionPane.showMessageDialog(null, "El numero " + numero + " es impar"); } } }

Resultados.

PROBLEMA 3 Identificar si un nmero entero es negativo, positivo cero Programa fuente importjavax.swing.JOptionPa ne; public class PositivoNegativo { public static void main( String args[] ) { StringNumero; String resultado; int numero; Numero = JOptionPane.showInputDialog(" Escriba el nmero: "); numero = Integer.parseInt( Numero); resultado = " "; if ( numero > 0 ) resultado = resultado + numero + " es un nmero positivo "; else if ( numero == 0) resultado = resultado + numero + " es cero "; else resultado = resultado + numero + " es un nmero negativo ";

JOptionPane.showMessageDialog(null, resultado, " Resultados de lacomparacin ", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }

Resultados.

PRUEBA DE ESCRITORIO (PROGRAMA ASCENDENTE) a) 15, 21, 18 a=15 b= 21 c=18 nm.1=15 nm.2=21 nm.3=18 if (15>18) (Falso) if (15>18) (Falso)

Orden = (a,c,b) Orden ascendente = 15,18,21

b) 21,15,18 a=21 b=15 c=18 nm.1=15 nm.2=21 nm.3=18 if (21>15) (Verdadero) if (15>18) (Falso)

Orden = (b,c,a) Orden ascendente = 15,18,21

c) 15,18,21 a=15b=18 c=21 nm.1=15 nm.2=18 nm.3=21 if (15>18)(Falso) if (15>21) if (18>21) (Falso) (Falso)

Orden = (a,b,c) Orden ascendente =15,18,21

d) 18,15,21 a= 18 b=15 c=21 nm.1=18 nm.2=15 nm.3=21 if (18>15) (Verdadero) if (18>21) (Falso)

Orden = (b,a,c) Orden ascendente =15,18,21

e) 18,21,15 a=18 b=21 c=15 nm.1=18 nm.2=21 nm.3=15 if (18>21) (Falso) if (18>15) (Verdadero)

Orden = (c,a,b) Orden ascendente =15,18,21

f) 21, 18,15 a=21 b=18 c=15 nm.1=21 nm.2=18 nm.3=15 if (21>18) (Verdadero) if (21>15) (Verdadero)

if (18>15) (Verdadero) Orden = (c,b,a) Orden ascendente =15,18,21

Das könnte Ihnen auch gefallen