You are on page 1of 3

/*3.

-Escribir un programa utilizando m�todos que presente un men� de opciones que


perminta elegir y realizar cada una de las siguientes tareas:
1.-Leer 2 N� enteros positivos N1, N2.
2.-Calcular la suma de los digitos de N1, de N2. Reportar.
3.-Invertir N1, N2. Reportar
4.-Determinar si es primo N1.N2
5.-Terminar
*/
package opc3;

import java.io.*;
public class OPC3
{static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
///////////////////////////////////////////////////////////////////////////////
public static void main(String[]args)throws IOException
{ int N1=0, N2=0,sum1,sum2,inv1,inv2,P1,P2;
int opc;
do { opc=menu();
switch(opc)
{case 1:
N1=LeerN("Ingrese N1 : ");
N2=LeerN("Ingrese N2 : ");

break;
case 2: if(N1!=0)
{sum1=suma(N1);
sum2=suma(N2);
Reportar("Suma de digitos de N1 :", sum1);
Reportar("Suma de digitos de N2 :", sum2);
}
break;

case 3: if(N1!=0)
{inv1=Invertido(N1);
inv2=Invertido(N2);
Reportar("Invertir N1 :",inv1);
Reportar("Invertir N2: ",inv2);
}
break;
case 4: if(N1!=0)
{P1=Primo(N1);
P2=Primo(N2);
Reportar("El numero N1: ",P1);
Reportar("El numero N2 : ",P2);
}
break;

case 5: terminar();
break;
}
}
while(opc!=5);
}
///////////////////////////MENU////////////////////////////////////////////////////
///////////////////////////
static int menu()throws IOException

{int opc;
do{System.out.println("Menu");
System.out.println("1.-Leer N1, N2");
System.out.println("2.-Calcular la suma de digitos de N1 Y N2 ");
System.out.println("3.-Invertir N1 Y N2");
System.out.println("4.-Determinar si es primo ");
System.out.println("5.-Terminar");
System.out.println("Selecciionar una opci�n[1-5]");
opc=Integer.parseInt(br.readLine());
}
while(opc<1||opc>5);
return opc;
}
/////////////////////////////////LEER (N)///////////////////////////////////////
static int LeerN(String mens)throws IOException
{int N;
do{
System.out.println(mens);
N=Integer.parseInt(br.readLine());
}while(N<=0);
return N;}
///////////////////////Invertir el n�mero//////////////////////////////////////
static int Invertido(int N)throws IOException
{int Ninv=0, res;
while(N>0)
{res=N%10;
Ninv=Ninv*10+res;
N=N/10;
}
return Ninv;
}

/////////////////////Suma de digitos//////////////////////////////////////////
static int suma(int N)throws IOException
{int res, sd=0;
while(N>0)
{res=N%10;
sd=sd+res;
N=N/10;
}
return sd;
}
///////////////////////Primo///////////////////////////////////////////////////
static int Primo (int N)throws IOException
{int c, cd=0;
for(c=1;c<=N;c++)
{if(N%c==0)
{cd=cd+1;
}
else{
}

}
if(cd==2)
{System.out.println("Es un numero primo"+N);
}
else{System.out.println("No es un numero primo");
}
return cd;
}
/////////////////////////////////////REPORTAR///////////////////////////////////
static void Reportar (String Mensaje, int X)throws IOException
{System.out.println("\n"+Mensaje+" = "+X);
return;
}

//////////////////////////////TERMINAR //////////////////////////////////////////
static void terminar()throws IOException
{System.out.println("Fin del programa...");

You might also like