For any element in keysList with a value greater than 60, print the corresponding value in itemsList, followed by a semicolon (no spaces). Ex: If keysList = {32, 105, 101, 35} and itemsList = {10, 20, 30, 40}, print: 20;30;

Respuesta :

Answer:

Below are the python Program for the above question:

Explanation:

keysList =[1,61,68,64]#key list items.

itemsList =[1,2,3,4]#item list items.

for x in range(len(keysList)):#for loop.

   if(keysList[x]>60):#check the value to be greator.

       print(itemsList[x],end=";")#print the value.

Output:

  • The above code will print as "2;3;4;".

Code Explanation:

  • The above code is in python language, in which the first and second line of the code defines a list. That list can be changed by the user when he wants.
  • Then there is a or loop that scans the keylist items and matches the items that it is greater than 60 or not. If it then takes the location and prints the itemlist by the help of that location.

Answer:

Following are the program in Java language

import java.util.Scanner;  // import package

class Main  // main class

{

public static void main (String [] args)   // main method

{

int k=0; // variable declaration // declaration of variable  

final int size = 4;  // declared the constant variable  

int[] keysList = new int[size];  // declared the array of keysList

int[] itemsList = new int[size];  // // declared the array of itemsList

keysList[0] = 32;  // storing the value in KeysList

keysList[1] = 105;  // storing the value in KeysList

keysList[2] =101;  // storing the value in KeysList

keysList[3] = 35; // storing the value in KeysList

itemsList[0] = 10; // storing the value in itemList

itemsList[1] = 20; // storing the value in itemLis

itemsList[2] = 30; // storing the value in itemLis

itemsList[3] = 40; // storing the value in itemLis

while(k<itemsList.length)  // iterating the loop

{

if(keysList[k]>60)  // check the condition

{

System.out.print(itemsList[k]);  // display the value

System.out.print(";");    //print space

}

k++;  // increment of k by 1

}

}

Output:

20;30;

Explanation:

Following are the description of Program

  • Create a variable "k" and Initialized with "0".
  • Declared a constant variable "size" with the value 4.
  • Declared the array  "keysList"  and " itemsList" also their value will be initialized.
  • After that iterating the while loop and check the condition of keysList array with a value greater than 60 then display the corresponding value in itemsList.
ACCESS MORE