ESCRIBIR UN PROGRAMA
Jhian Castro ArceTarea16 de Abril de 2019
1.588 Palabras (7 Páginas)114 Visitas
/*ESCRIBIR UN PROGRAMA UTILIZANDO METODOS QUE PRESENTEN UN MENU DE OPCIONES QUE PERMITA ELEGIR Y REALIZAR CADA UNA DE LAS SIGUIENTES TAREAS:
a= leer un N° entero positivo n1,n2.
b= calcular la potencia de n1 a la n2 por multiplicaciones sucesivas.reportar.
c= calcular el MCM. reportar el mcm.
d= calcular la suma de digitos de n1 y suma de digitos de n2.reportar
e= terminar
EL PROGRAMA SE REPITE MIENTRAS NO SELECIONE LA OPCION TERMINAR
*/
package nextclass;
import java.io.*;
public class Nextclass {
static BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
public static void main(String[] args)throws IOException {
int N1=0,N2=0,mcm,p,s1,s2;
char opc;
do{ opc=Menu();
switch(opc){
case 'a' : N1=LeerN("Ingrese n1: ");
N2=LeerN("Ingrese n2: ");
break;
case 'b' : if(N1!=0){
p=Potencia(N1,N2);
Reportar("La potencia es: ",p);
}else {mensaje();
}
break;
case 'c' : if(N1!=0){
mcm=MInComMul(N1,N2);
Reportar("El MCM es: ",mcm);
}else{mensaje();
}
break;
case 'd' : if(N1!=0){
s1=SumDig(N1);
Reportar("La suma de digitos de es: ",s1);
s2=SumDig(N2);
Reportar("La suma de digitos de es: ",s2);
}else { mensaje();
}
break;
case 'e' : terminar();
break;
}
}while(opc!='e');
}
static char Menu()throws IOException{
char opc;
do{
System.out.println("Menu:");
System.out.println("a: Ingrese los numeros n1 y n2");
System.out.println("b: Mostrar potencia");
System.out.println("c: Mostrar si MCM");
System.out.println("d: Mostrar la cantidad de digitos:");
System.out.println("e: Terminar Programa");
System.out.println("Ingresar una opcion a realizar");
opc=br.readLine().toLowerCase().charAt(0);
}while(opc<'a'||opc>'e');
return opc;
}
static int LeerN (String mensaje) throws IOException{
int n;
do{
System.out.println("Ingrese los numero: ");
n=Integer.parseInt(br.readLine());
}while(n<=0);
return n;
}
static int Potencia(int N1, int N2)throws IOException{
int c,pot=1;
for(c=1;c<=N2;c=c+1){
pot=pot*N1;
}
return pot;
}
static int MInComMul(int N1, int N2)throws IOException{
int d=2,mcm=1;
while (N1>1 || N2>1)
{
if(N1%d==0 || N2%d==0)
{
if(N1%d==0)
{
N1=N1/d;
}
if (N2%d==0)
...