Array
Publicado por alex (1 intervención) el 21/10/2017 17:17:43
Hola:
Alguien me puede explicar porque el texto comentado no realiza la misma operación que el que no?
gracias
Alguien me puede explicar porque el texto comentado no realiza la misma operación que el que no?
gracias
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
public static void main(String[] args) {
// TODO code application logic here
A<String> l = (s)->System.out.println(s);
A<String> p = (s)->System.out.print(s);
int numeros[];
Scanner sc = new Scanner (System.in);
System.out.print("introduce tamaño array ");
int array = sc.nextInt();
System.out.println("El tamaño del array es "+array);
numeros = new int[array];
for(int i=0; i<numeros.length; i++){
Scanner sc2 = new Scanner (System.in);
System.out.print("introduce numero entero: ");
numeros[i]=sc.nextInt();
}
int menor = numeros[0];
int mayor = numeros[0];
int suma = numeros[0];
// for(int v=0 ; v<numeros.length; v++){
//
// if(mayor<v) mayor=v;
// if(menor>v) menor=v;
// suma+= v;
// }
for(int v: numeros){
if(mayor<v) mayor=v;
if(menor>v) menor=v;
suma+= v;
}
l.out("Elemento mayor = " +mayor);
l.out("Elemento menor = " +menor);
l.out("Suma de todos = " +suma);
}
Valora esta pregunta
0