Respuesta :
Answer:
int[]RandArray = new RandArray[10];
for(int x =0; x< RandArray.length;x++){
RandArray[x] = random.nextInt(10 - 1 + 1) + 1;
}
for(int x =0; x< RandArray.length;x++){
int og = RandArray[x];
if(RandArray[x]<x){
RandArray[x] = x + 10;
}
else if(RandArray[x] == x){
RandArray[x] =RandArray[x] * 2;
}
else if(RandArray[x] > x){
RandArray[x] =Math.pow(x,2);
}
System.out.println("Original: " + og +"New: "+ " RandArray[x])
}
Explanation:
Following are the python program for calculating the array values by using the random array function:
Python Program:
import random as R#import package of random
R1 = R.sample(range(1, 20), 10) #Generating 10 random numbers from 1 to 20
RandArray = R1.copy() #Copying the elements of R1 in to RandArray
print("Original Array: ",RandArray)#defining the print method that prints RandArray value
for e in range(len(RandArray)):#defining a loop that calculates
if(RandArray[e] < e):#defining if block that checks index of list that stores random number
RandArray[e] = e+10#adding 10 in numbers
elif(RandArray[e] == e):#defining if block that checks index of list that stores random number
RandArray[e] = e*2#multiplying by 2 in number
elif(RandArray[e] > e):#defining if block that checks index of list that stores random number
RandArray[e] = e**2#calculating the square value of RandArray
print("Changed Array: ",RandArray)#print RandArray value
for i in range(10):#defining loop that prints Array value
print("Original Number:",R1[i], "Changed Number:",RandArray[i])#print RandArray value
Output:
Please find the attached file.
Program Explanation:
- import package of random.
- Defining the "R1" variable that uses a random function to generate 10 random numbers from 1 to 20.
- Declaring the "RandArray" that Copying the elements of R1 into RandArray.
- Defining a loop that calculates the length of the array and uses a conditional block that checks and calculates the random array values.
- In the last step, another loop is declared that prints the array "RandArray" value.
Find out more information about the random number here:
brainly.com/question/16403687
