-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModificarArray2.java
More file actions
28 lines (19 loc) · 846 Bytes
/
Copy pathModificarArray2.java
File metadata and controls
28 lines (19 loc) · 846 Bytes
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
import java.util.Scanner;
public class ModificarArray2 {
public static void modificarArray(int[] arr, int factor) {
for (int i = 0; i < arr.length; i++) {
arr[i] *= factor;
}
System.out.println("Dentro del método: " + java.util.Arrays.toString(arr));
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] numeros = {1, 2, 3, 4, 5};
System.out.println("Antes de modificar: " + java.util.Arrays.toString(numeros));
System.out.print("Introduce el número por el que deseas multiplicar los valores del arreglo: ");
int factor = scanner.nextInt();
modificarArray(numeros, factor);
System.out.println("Después de modificar: " + java.util.Arrays.toString(numeros));
scanner.close();
}
}