Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-e003
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
Silvia Barrientos
java-e003
Commits
b3d62ccf
Commit
b3d62ccf
authored
Sep 14, 2020
by
Silvia Barrientos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tarea
parents
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
184 additions
and
0 deletions
+184
-0
Ejercicio01.java
+29
-0
Ejercicio02.java
+72
-0
Ejercicio03.java
+79
-0
README.md
+4
-0
No files found.
Ejercicio01.java
0 → 100644
View file @
b3d62ccf
import
java.util.ArrayList
;
public
class
Ejercicio01
{
static
final
int
DIMENSIONLIST
=
10
;
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
Integer
>
listaRandom
=
new
ArrayList
<
Integer
>();
boolean
esprimo
;
int
contador
;
for
(
int
i
=
0
;
i
<
DIMENSIONLIST
;
i
++){
listaRandom
.
add
((
int
)(
Math
.
random
()*
50
+
1
));
}
System
.
out
.
print
(
listaRandom
);
for
(
int
i
=
0
;
i
<
DIMENSIONLIST
;
i
++){
esprimo
=
true
;
contador
=
2
;
while
(
contador
<=
(
listaRandom
.
get
(
i
)/
2
)
&&
esprimo
){
if
(
listaRandom
.
get
(
i
)
%
contador
==
0
){
esprimo
=
false
;
}
contador
++;
}
if
(
esprimo
){
System
.
out
.
printf
(
"\t %d \t "
,
listaRandom
.
get
(
i
));
}
}
}
}
Ejercicio02.java
0 → 100644
View file @
b3d62ccf
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.Collections
;
public
class
Ejercicio02
{
static
final
int
DIMENSIONLIST
=
10
;
static
final
int
X
=
-
50
;
static
final
int
Y
=
50
;
public
static
void
main
(
String
[]
args
)
{
LinkedList
<
Integer
>
lista
=
new
LinkedList
<
Integer
>();
int
num
;
lista
.
add
(
0
);
for
(
int
i
=
0
;
i
<
DIMENSIONLIST
;
i
++
){
num
=
(
int
)(
Math
.
random
()*(
X
-
Y
+
1
)+
Y
);
if
(
num
>=
0
){
lista
.
addLast
(
num
);
}
else
{
lista
.
addFirst
(
num
);
}
}
System
.
out
.
print
(
lista
);
ArrayList
<
Integer
>
listaNegativos
=
new
ArrayList
<
Integer
>();
ArrayList
<
Integer
>
listaPositivos
=
new
ArrayList
<
Integer
>();
for
(
int
i
=
0
;
i
<
lista
.
size
();
i
++){
if
(
lista
.
get
(
i
)
<
0
){
listaNegativos
.
add
(
lista
.
get
(
i
));
}
else
{
listaPositivos
.
add
(
lista
.
get
(
i
));
}
}
System
.
out
.
printf
(
"\n\t"
+
listaNegativos
+
"\n"
);
System
.
out
.
printf
(
"\t"
+
listaPositivos
+
"\n"
);
mayorMenor
(
listaNegativos
,
listaPositivos
);
ordenarListas
(
listaNegativos
,
listaPositivos
);
}
public
static
void
mayorMenor
(
ArrayList
<
Integer
>
negativos
,
ArrayList
<
Integer
>
positivos
){
int
mayor
=
X
;
int
menor
=
Y
;
for
(
int
i
=
0
;
i
<
negativos
.
size
();
i
++){
if
(
mayor
<
negativos
.
get
(
i
)){
mayor
=
negativos
.
get
(
i
);
}
if
(
menor
>
negativos
.
get
(
i
)){
menor
=
negativos
.
get
(
i
);
}
}
System
.
out
.
printf
(
"El valor mayor de la lista de negativos es: "
+
mayor
+
"\n"
);
System
.
out
.
printf
(
"El valor menor de la lista de negativos es: "
+
menor
+
"\n"
);
mayor
=
X
;
menor
=
Y
;
for
(
int
i
=
0
;
i
<
positivos
.
size
();
i
++){
if
(
mayor
<
positivos
.
get
(
i
)){
mayor
=
positivos
.
get
(
i
);
}
if
(
menor
>
positivos
.
get
(
i
)){
menor
=
positivos
.
get
(
i
);
}
}
System
.
out
.
printf
(
"El valor mayor de la lista de positivos es: "
+
mayor
+
"\n"
);
System
.
out
.
printf
(
"El valor menor de la lista de positivos es: "
+
menor
+
"\n"
);
}
public
static
void
ordenarListas
(
ArrayList
<
Integer
>
negativos
,
ArrayList
<
Integer
>
positivos
){
Collections
.
sort
(
negativos
);
Collections
.
sort
(
positivos
);
System
.
out
.
printf
(
"\n"
+
negativos
);
System
.
out
.
printf
(
"\n"
+
positivos
);
}
}
Ejercicio03.java
0 → 100644
View file @
b3d62ccf
import
java.util.Scanner
;
public
class
Ejercicio03
{
static
final
int
REGISTROS
=
5
;
public
static
void
main
(
String
[]
args
)
{
ColeccionDeDatos
coleccion
=
new
ColeccionDeDatos
();
Scanner
entradaNombre
=
new
Scanner
(
System
.
in
);
Scanner
entradaApellido
=
new
Scanner
(
System
.
in
);
Scanner
entradaClave
=
new
Scanner
(
System
.
in
);
String
nombre
;
String
apellido
;
String
clave
;
for
(
int
i
=
0
;
i
<
REGISTROS
;
i
++){
System
.
out
.
print
(
"Ingrese nombre: "
);
nombre
=
entradaNombre
.
nextLine
();
System
.
out
.
print
(
"Ingrese apellido: "
);
apellido
=
entradaApellido
.
nextLine
();
coleccion
.
cargarLista
(
nombre
,
apellido
);
}
coleccion
.
imprimirListaDatos
();
System
.
out
.
print
(
"\nIngresar clave del primer elemento: "
);
clave
=
entradaClave
.
nextLine
();
coleccion
.
imprimirPorClave
(
clave
);
System
.
out
.
print
(
"\nIngresar clave del segundo elemento: "
);
clave
=
entradaClave
.
nextLine
();
coleccion
.
imprimirPorClave
(
clave
);
entradaApellido
.
close
();
entradaNombre
.
close
();
entradaClave
.
close
();
coleccion
.
imprimirListaDatos
();
}
}
class
ColeccionDeDatos
{
static
final
int
REGISTROS
=
5
;
class
Registro
{
String
clave
;
String
valor
;
public
Registro
(
String
nombre
,
String
apellido
){
clave
=
nombre
.
charAt
(
0
)
+
""
+
apellido
.
charAt
(
0
);
valor
=
nombre
+
" "
+
apellido
;
}
}
private
Registro
[]
listaDatos
=
new
Registro
[
REGISTROS
];
int
indice
=
0
;
public
void
cargarLista
(
String
nombre
,
String
apellido
)
{
Registro
temporal
=
new
Registro
(
nombre
,
apellido
);
if
(
indice
<
5
){
listaDatos
[
indice
]
=
temporal
;
indice
++;
}
else
{
System
.
out
.
print
(
"Ya no se pueden agregar registros"
);
}
}
public
void
imprimirListaDatos
()
{
System
.
out
.
print
(
"Clave\tValor\n"
);
for
(
int
i
=
0
;
i
<
REGISTROS
;
i
++)
{
System
.
out
.
print
(
listaDatos
[
i
].
clave
+
"\t"
+
listaDatos
[
i
].
valor
+
"\n"
);
}
}
public
void
imprimirPorClave
(
String
clave
)
{
System
.
out
.
print
(
"Clave\tValor\n"
);
if
(
clave
.
equals
(
listaDatos
[
0
].
clave
)){
System
.
out
.
print
(
listaDatos
[
0
].
clave
+
"\t"
+
listaDatos
[
0
].
valor
);
}
else
if
(
clave
.
equals
(
listaDatos
[
REGISTROS
-
1
].
clave
)){
System
.
out
.
print
(
listaDatos
[
REGISTROS
-
1
].
clave
+
"\t"
+
listaDatos
[
REGISTROS
-
1
].
valor
);
}
else
{
System
.
out
.
print
(
"\nNo se encontro la clave"
);
}
}
}
README.md
0 → 100644
View file @
b3d62ccf
Para compilar los ejercicos
-
Abrir el archivo en el editor de texto de preferencia.
-
Compilar el archivo (F5 en VisualStudio Code).
-
Se mostrar o requerira datos por consola.
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