Commit e5dbe836 by Cristian Caceres

validaciones numeros negativos y que no sean numeros

parent c8902b57
......@@ -3,8 +3,6 @@
*/
package calculadora;
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode;
/**
* @author cristian caceres
*
......@@ -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 {
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean bandera= false;
Scanner scan = new Scanner(System.in);
float numero1=0;
float numero2=0;
float numero1=-1;
float numero2=-1;
System.out.println("Ingrese dos nmeros");
System.out.println("Numero 1:");
while(!bandera) {
try {
numero1= scan.nextFloat();
bandera=true;
// valida que sea positivo y sea un numero
while(numero1<0) {
try {
numero1=Float.parseFloat(scan.nextLine()) ;
if(numero1<0) {
System.out.println("Ingrese de nuevo numero 1: ");
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Ingrese de nuevo numero 1: ");
}
}
System.out.println("Numero 2:");
while(bandera) {
try {
numero2= scan.nextFloat();
bandera=false;
// valida que sea positivo y sea un numero
while( numero2<0) {
try {
numero2= Float.parseFloat(scan.nextLine()) ;
if(numero2<0) {
System.out.println("Ingrese de nuevo numero 2: ");
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Ingrese de nuevo numero 2: ");
}
}
System.out.println("numero1 vale: "+ numero1);
......@@ -55,6 +63,10 @@ public class Main {
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 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