Commit e5dbe836 by Cristian Caceres

validaciones numeros negativos y que no sean numeros

parent c8902b57
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
*/ */
package calculadora; package calculadora;
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode;
/** /**
* @author cristian caceres * @author cristian caceres
* *
...@@ -112,6 +110,14 @@ public class Calculadora { ...@@ -112,6 +110,14 @@ public class Calculadora {
} }
public boolean ambosPrimos() {
if (esPrimoB() && esPrimoA()) {
return true;
}else {
return false;
}
}
......
...@@ -16,33 +16,41 @@ public class Main { ...@@ -16,33 +16,41 @@ public class Main {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
boolean bandera= false;
Scanner scan = new Scanner(System.in); Scanner scan = new Scanner(System.in);
float numero1=0; float numero1=-1;
float numero2=0; float numero2=-1;
System.out.println("Ingrese dos nmeros"); System.out.println("Ingrese dos nmeros");
System.out.println("Numero 1:"); System.out.println("Numero 1:");
while(!bandera) { // valida que sea positivo y sea un numero
try { while(numero1<0) {
numero1= scan.nextFloat(); try {
bandera=true; numero1=Float.parseFloat(scan.nextLine()) ;
if(numero1<0) {
System.out.println("Ingrese de nuevo numero 1: ");
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
System.out.println("Ingrese de nuevo numero 1: "); System.out.println("Ingrese de nuevo numero 1: ");
} }
} }
System.out.println("Numero 2:"); System.out.println("Numero 2:");
while(bandera) { // valida que sea positivo y sea un numero
try { while( numero2<0) {
numero2= scan.nextFloat();
bandera=false; try {
numero2= Float.parseFloat(scan.nextLine()) ;
if(numero2<0) {
System.out.println("Ingrese de nuevo numero 2: ");
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
System.out.println("Ingrese de nuevo numero 2: "); System.out.println("Ingrese de nuevo numero 2: ");
} }
} }
System.out.println("numero1 vale: "+ numero1); System.out.println("numero1 vale: "+ numero1);
...@@ -55,6 +63,10 @@ public class Main { ...@@ -55,6 +63,10 @@ public class Main {
System.out.println("el mod de numero1 & numero2 es: "+cal.mod()); System.out.println("el mod de numero1 & numero2 es: "+cal.mod());
System.out.println("el numero 1 es primo?: "+ cal.esPrimoA()); System.out.println("el numero 1 es primo?: "+ cal.esPrimoA());
System.out.println("el numero 2 es primo?: "+ cal.esPrimoB()); System.out.println("el numero 2 es primo?: "+ cal.esPrimoB());
System.out.println("ambos numeros son primos?: "+cal.ambosPrimos());
scan.close();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment