Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
Dia_001
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
William Gonzalez
Dia_001
Commits
274264de
Commit
274264de
authored
Oct 22, 2021
by
willgonzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
Toros_Vacas.java
+100
-0
No files found.
Toros_Vacas.java
0 → 100644
View file @
274264de
import
java.util.Scanner
;
public
class
Toros_Vacas
{
public
static
void
main
(
String
[]
args
)
{
String
NumA
;
String
NumB
;
int
Vacas
=
0
;
int
Toros
=
0
;
String
[]
NumbIntentados
=
new
String
[
12
];
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Favor ingrese el Numero del Jugador A: "
);
NumA
=
scanner
.
nextLine
();
char
Recorrido
;
int
i
;
for
(
i
=
0
;
i
<
12
;
i
++){
System
.
out
.
print
(
"Intento B "
+(
i
+
1
)+
": "
);
NumB
=
scanner
.
nextLine
();
//validados que el formato sea correcto
for
(;
NumB
.
length
()!=
4
;){
System
.
out
.
println
(
"Jugada Invalida: Jugada con Formato Incorrecto"
);
System
.
out
.
println
(
"favor Ingrese una jugada valida: "
);
NumB
=
scanner
.
nextLine
();
}
//validados que los digitos no sean repetidos y volvemos a mirar el formato
for
(
int
j
=
0
;
j
<
3
;
j
++){
for
(
int
k
=
j
+
1
;
k
<
4
;
k
++){
if
(
NumB
.
charAt
(
j
)==
NumB
.
charAt
(
k
)){
System
.
out
.
println
(
"Jugada Invalida - Numero Con digitos repetidos"
);
System
.
out
.
println
(
"favor Ingrese una jugada valida"
);
NumB
=
scanner
.
nextLine
();
j
=
0
;
k
=
j
+
1
;
for
(;
NumB
.
length
()!=
4
;){
System
.
out
.
println
(
"Jugada Invalida: Jugada con Formato Incorrecto"
);
System
.
out
.
println
(
"favor Ingrese una jugada valida: "
);
NumB
=
scanner
.
nextLine
();
}
};
}
}
//validamos que anteriormente no se haya ingresado ya el numero, al igual que no se repitan los digitos y que el formato sea correcto
for
(
int
j
=
0
;
j
<
i
;
j
++){
if
(
NumB
.
equals
((
NumbIntentados
[
j
]))){
System
.
out
.
println
(
"Jugada Invalida - El numero INGRESADO ya a sido insertado anteriormente, favor ingrese otro"
);
NumB
=
scanner
.
nextLine
();
j
=
0
;
for
(
int
l
=
0
;
l
<
3
;
l
++){
for
(
int
k
=
l
+
1
;
k
<
4
;
k
++){
if
(
NumB
.
charAt
(
l
)==
NumB
.
charAt
(
k
)){
System
.
out
.
println
(
"Jugada Invalida - Numero Con digitos repetidos"
);
System
.
out
.
println
(
"favor Ingrese una jugada valida"
);
NumB
=
scanner
.
nextLine
();
l
=
0
;
k
=
l
+
1
;
for
(;
NumB
.
length
()!=
4
;){
System
.
out
.
println
(
"Jugada Inválida: Jugada con Formato Incorrecto"
);
System
.
out
.
println
(
"favor Ingrese una jugada valida: "
);
NumB
=
scanner
.
nextLine
();
}
};
}
}
}
}
char
P0
,
P1
,
P2
,
P3
;
P0
=
NumA
.
charAt
(
0
);
P1
=
NumA
.
charAt
(
1
);
P2
=
NumA
.
charAt
(
2
);
P3
=
NumA
.
charAt
(
3
);
for
(
int
k
=
0
;
k
<
4
;
k
++){
if
(
NumB
.
charAt
(
k
)==(
P0
)
||
NumB
.
charAt
(
k
)==(
P1
)
||
NumB
.
charAt
(
k
)==(
P2
)
||
NumB
.
charAt
(
k
)==(
P3
)){
Vacas
++;
}
}
if
(
NumB
.
charAt
(
0
)==(
P0
))
Toros
++;
if
(
NumB
.
charAt
(
1
)==(
P1
))
Toros
++;
if
(
NumB
.
charAt
(
2
)==(
P2
))
Toros
++;
if
(
NumB
.
charAt
(
3
)==(
P3
))
Toros
++;
//System.out.println("vacas= "+Vacas);
Vacas
-=
Toros
;
if
(
Toros
==
4
){
System
.
out
.
println
(
"Respuesta A :"
+
Toros
+
" Toros, "
+
Vacas
+
" Vacas"
);
System
.
out
.
println
(
"Fin del Juego - Gano B en "
+(
i
+
1
)+
" intentos"
);
break
;
}
System
.
out
.
println
(
"Numero A: "
+
NumA
);
System
.
out
.
println
(
"Intento B "
+(
i
+
1
)+
" "
+
NumB
);
System
.
out
.
println
(
"Respuesta A :"
+
Toros
+
" Toros, "
+
Vacas
+
" Vacas"
);
Vacas
=
0
;
Toros
=
0
;
NumbIntentados
[
i
]=
NumB
;
}
if
(
i
==
12
){
System
.
out
.
println
(
"Fin del Juego- Gano A"
);
}
}
}
\ No newline at end of file
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