Java - Generar 50 números aleatorios entre 0 y 100 y almacenarlo en un arreglo(JDK)

 
Vista:

Generar 50 números aleatorios entre 0 y 100 y almacenarlo en un arreglo(JDK)

Publicado por Theseap (4 intervenciones) el 06/10/2020 01:39:40
hola necesito ayuda con unos ejercicios si me pudieran ayudar.
-Generar 50 números aleatorios entre 0 y 100 y almacenarlo en un arreglo. Luego
mostrar los números que son pares.(este lo e logrado hacer, pero los otros me a costado e alguno sin saber como empezar. dejo el codigo de este)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class RandomPar {
 
	private int[] arreglo;
	Random numeros;
 
	public RandomPar() {
 
		numeros = new Random();
		arreglo= new int [50];
		for (int i=0 ; i<arreglo.length;i++) {
			int n = numeros.nextInt(100);
			arreglo[i]= n;
		}
	}
 
 
	public void EsPar() {
		System.out.println("Los numeros random pares que se obtuvo fueron:");
		for (int i=0 ; i<arreglo.length;i++) {
			if (arreglo[i]%2==0) {
 
				System.out.println(arreglo[i]);
			}
		}
	}
 
	public static void main (String []args) {
		RandomPar NumerosRandom = new RandomPar();
 
		NumerosRandom.EsPar();
	}
 
 
}
-Leer 10 palabras y almacenarlos en un arreglo. Mostrar todas las palabras leídas y
mostrar las palabras que comiencen con una determinada letra. Se debe leer la letra.
-Leer un texto, reemplazar las vocales minúsculas por mayúsculas y mostrar el texto
con el cambio.
Se lee: Hola como estas se debe mostrar: HOlA cOmO EstAs
-Leer 3 textos y unirlos en uno solo, luego quitar los caracteres #, @, +, - y & que se
encuentre en el texto. Mostrar el texto sin los caracteres #, @, +, - y &.
se lee: hol@ c#mo estas +o -¿ && texto a mostrar: hol cmo estas o ¿
-Leer nombres hasta que se ingrese la palabra stop. Los nombres leídos guardarlos en
una lista y mostrar los que comiencen con una vocal.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder

Generar 50 números aleatorios entre 0 y 100 y almacenarlo en un arreglo(JDK)

Publicado por Pedro (3 intervenciones) el 13/12/2020 03:18:00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
 
public class Theseap {
 
    public static Integer getRandomNumber(int min, int max) {
        return new Random().nextInt(max - min + 1) + min;
    }
 
    public static int[] get50NumerosAleatorios() {
        int[] numeros = new int[50];
        for (int i = 0; i < numeros.length; i++) {
            numeros[i] = getRandomNumber(0, 100);
        }
        return numeros;
    }
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] numerosAleatorios = get50NumerosAleatorios();
        System.out.println("A continuación los números pares de los números aleatorios:");
        for (int i = 0; i < numerosAleatorios.length; i++) {
            if (numerosAleatorios[i] % 2 == 0) {
                System.out.print(numerosAleatorios[i] + " ");
            }
        }
 
        System.out.println("\nAhora vamos a leer 10 palabras");
        String[] words = new String[10];
 
        for (int i = 0; i < words.length; i++) {
            System.out.print("Palabra " + (i + 1) + ": ");
            words[i] = sc.nextLine();
        }
        System.out.print("\nA continuación las plabras: ");
        for (int i = 0; i < words.length; i++) {
            System.out.print(words[i] + (i + 1 < words.length ? ", " : "\n"));
        }
 
        System.out.print("\nIntroduce una \"determinada\" letra: ");
        String letra = sc.nextLine();
        int cantidadPalabrasDeterminadas = 0;
        for (String word : words) {
            if (word.toLowerCase().startsWith(letra.toLowerCase())) {
                cantidadPalabrasDeterminadas++;
            }
        }
        if (cantidadPalabrasDeterminadas == 0) {
            System.out.println("Parece que no hay palabras que empiecen con la \"determinada\" letra");
        } else {
            int c = 0;
            System.out.print("A continuación las palabras que empiezan con la \"determinada\" letra: ");
            for (String word : words) {
                if (word.toLowerCase().startsWith(letra.toLowerCase())) {
                    c++;
                    System.out.print(word + (c + 1 < cantidadPalabrasDeterminadas ? ", " : "\n"));
                }
            }
        }
 
        System.out.print("\nAhora vamos a leer un texto y vamos a reemplazar las vocales: ");
        String texto = sc.nextLine();
        texto = texto.replaceAll("a", "A")
                .replaceAll("e", "E")
                .replaceAll("i", "I")
                .replaceAll("o", "O")
                .replaceAll("u", "U");
        System.out.println("texto: " + texto);
 
        String[] textos = new String[3];
        System.out.println("\nAhora vamos a leer 3 textos y vamos a #, @, +, - y & que se encuentre en el texto");
        for (int i = 0; i < textos.length; i++) {
            System.out.print("Testo #" + (i + 1) + ": ");
            textos[i] = sc.nextLine();
        }
 
        String textos3 = (textos[0] + textos[1] + textos[2])
                .replaceAll("#", "")
                .replaceAll("@", "")
                .replaceAll("+", "")
                .replaceAll("-", "")
                .replaceAll("&", "");
        System.out.println("textos3: " + textos3);
 
        List<String> nombres = new ArrayList();
        System.out.println("\nAhora vamos a leer nombres hasta que se ingrese la palabra stop:");
        String nombre;
        while (true) {
            System.out.print("Inserte nombre: ");
            nombre = sc.nextLine();
            if (nombre.equals("stop")) {
                break;
            } else {
                nombres.add(nombre);
            }
        }
        System.out.print("A continuación los nombres: ");
        for (int i = 0; i < nombres.size(); i++) {
            System.out.print(nombres.get(i) + (i + 1 < nombres.size() ? ", " : "\n"));
        }
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar