Java - Random

 
Vista:
sin imagen de perfil

Random

Publicado por Andre (4 intervenciones) el 03/02/2016 21:08:18
Ayuda!
Esto es programacion basica
Tengo que declarar un arreglo de forma aleatoria (random) con un rango de 3 a 7 posiciones e identificar el numero menor y mayor (tengo que introducir datos)
La posicion menor y mayor
El tamaño del arreglo


Solo llevo hecho el arreglo y he mostrado su tamaño


1
2
3
Scanner leer=new Scanner (System.in);
int a []=new int [(int)(Math.random()*7-3+1)+3];
System.out.println("El tamaño del arreglo es: "+a.length);
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Random

Publicado por Alvaro (11 intervenciones) el 03/02/2016 23:41:11
Creo que esto te puede ayudar echale un ojo un saludo.


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
import java.util.Scanner;
 
public class Array {
 
	public static void main(String[] args) {
 
		int x = (int) (Math.random() * 4 + 4);
		int y = 0;
 
		Scanner teclado = new Scanner(System.in);
 
		int[] arreglo = new int[x];
 
		for (int i = 0; i < arreglo.length; i++) {
			System.out.println("Inserte un nuemro");
			arreglo[i] = teclado.nextInt();
 
		}
 
		System.out.println("EL array tiene un tamaño de " + arreglo.length + " posiciones.");
 
		x = arreglo[0];
		y = 1;
		for (int i = 1; i < arreglo.length; i++) {
			if (arreglo[i] > x) {
				x = arreglo[i];
				y = i + 1;
			}
 
		}
		System.out.println("El numero mas alto es :" + x + ". Y estaba en la posicion: " + y);
 
		x = arreglo[0];
		y = 1;
		for (int i = 1; i < arreglo.length; i++) {
			if (arreglo[i] < x) {
				x = arreglo[i];
				y = i + 1;
 
			}
		}
		System.out.println("El numero mas bajo es :" + x + ". Y estaba en la posicion: " + y);
 
	}
 
}
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