0% found this document useful (0 votes)
12 views1 page

C7 E4

This Java program initializes an array of integers with random values between 0 and 9. It prompts the user to input a value between 0 and 10, which is then inserted at the beginning of the array, shifting the other elements to the right. The program includes methods for loading the array, printing its contents, and handling user input.

Uploaded by

Pedro Petersen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

C7 E4

This Java program initializes an array of integers with random values between 0 and 9. It prompts the user to input a value between 0 and 10, which is then inserted at the beginning of the array, shifting the other elements to the right. The program includes methods for loading the array, printing its contents, and handling user input.

Uploaded by

Pedro Petersen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.io.

BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;

class C7_E4 {
public static final int MAX = 10;
public static final int MINVALOR = 0;
public static final int MAXVALOR = 9;

public static void main (String [ ] args) {


int [ ] arrenteros = new int[MAX];
BufferedReader entrada = new BufferedReader(new
InputStreamReader(System.in));
try {
cargar_arreglo(arrenteros);
imprimir_arreglo(arrenteros);
System.out.println("Ingrese un valor entre 0 y 10
exclusivamente");
int val = Integer.valueOf(entrada.readLine());
inserte_y_corrimiento_derecha(arrenteros, val);
imprimir_arreglo(arrenteros);
}
catch (Exception exc) {
System.out.println(exc);
}
}
public static void inserte_y_corrimiento_derecha(int [] arr, int val){
for(int pos = MAX-1; pos > 0; pos--){
arr[pos] = arr[pos-1];
}
arr[0] = val;
}

public static void cargar_arreglo(int [] arr) {


Random r = new Random();
for (int pos = 0; pos < MAX; pos++) {
arr[pos] = (r.nextInt(MAXVALOR - MINVALOR + 1) + MINVALOR);
}
}

public static void imprimir_arreglo(int [] arr) {


for (int pos = 0; pos < MAX; pos++) {
System.out.print("[" + arr[pos] + "]");
}
System.out.println("");
}
}

You might also like