Create an array of size 10 and name RandArray populate the RandArray with random integer from 1 to 20. Every element in the RandArray must be changed as follows: If the value of the element is less than the array index, the element must be replaced with the index plus 10. If the value of the element is equal to the index, the element must be doubled. If the value of the element is greater than the index, the element must be replaced by the index squared. Print the original number and the changed number of the RandArray

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

Ver imagen codiepienagoya