Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-e002
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cristian Caceres
java-e002
Commits
e5dbe836
Commit
e5dbe836
authored
Jul 09, 2019
by
Cristian Caceres
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validaciones numeros negativos y que no sean numeros
parent
c8902b57
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
15 deletions
+33
-15
calculadora/src/calculadora/Calculadora.java
+8
-2
calculadora/src/calculadora/Main.java
+25
-13
No files found.
calculadora/src/calculadora/Calculadora.java
View file @
e5dbe836
...
...
@@ -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
;
}
}
...
...
calculadora/src/calculadora/Main.java
View file @
e5dbe836
...
...
@@ -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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment