/*

Magallon Juan-Qui Inti Sandino
Algoritmos y Estructuras de Datos

ESTE GENERA UN PAQUETE LLAMADO algoritmos, SE TIENEN Q COMPILAR LOS DOS ARCHIVOS POR SEPARADO

*/

package algoritmos;

import java.io.*;

public class Leer
{
public static String dato()
{
String sdato = " ";
try
{
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader flujoE = new BufferedReader(is);
sdato = flujoE.readLine();
}
catch(IOException e)
{
System.err.println("Error: " + e.getMessage());
}
return sdato;
}

public static short datoShort()
{
try
{
return Short.parseShort(dato());
}
catch(NumberFormatException e)
{
return Short.MIN_VALUE;
}
}

public static int datoInt()
{
try
{
return Integer.parseInt(dato());
}
catch(NumberFormatException e)
{
return Integer.MIN_VALUE;
}
}

public static long datoLong()
{
try
{
return Long.parseLong(dato());
}
catch(NumberFormatException e)
{
return Long.MIN_VALUE;
}
}

public static float datoFloat()
{
try
{
Float f = new Float(dato());
return f.floatValue();
}
catch(NumberFormatException e)
{
return Float.NaN;
}
}

public static double datoDouble()
{
try
{
Double d = new Double(dato());
return d.doubleValue();
}
catch(NumberFormatException e)
{
return Double.NaN;
}
}
}

___________________________________________________________________

/*

Magallon Juan-Qui Inti Sandino
Algoritmos y Estructuras de Datos

*/


package algoritmos; //Para utilizar clase Leer

import java.io.*;

public class ParImpar
{ public static void main(String args[])
throws IOException
{
int opc,n,pares=0,impares=0;
Leer lee = new Leer(); //usa el metodo de la clase Leer del paquete algoritmos
System.out.println("PROGRAMA QUE DETERMINA SI UN NUMERO ES PAR O IMPAR ");
do
{
do
{
System.out.println("*****M E N U*****\n");
System.out.println(" 1.LEER NUMERO ");
System.out.println(" 2.MOSTRAR CONTADOR");
System.out.println(" 3.SALIR");
System.out.print("\nOPCION: ");
opc = lee.datoInt();
System.out.println("\n");
}while(opc<1||opc>3);

switch(opc)
{
case 1:System.out.println("Proporcione numero");
n = lee.datoInt();
if((n%2)==0)
{
System.out.println("El numero " + n + " es par");
pares++;
}
else
{
System.out.println("El numero " + n + " es impar");
impares++;
}
break;
case 2:System.out.println("El numero de pares es :" + pares);
System.out.println("El numero de impares es:" + impares); break;
}
}while(opc!=3);
}
}

 

 

Hosted by www.Geocities.ws

1