6.0k views
1 vote
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;

User Tovare
by
4.6k points

2 Answers

3 votes

Final answer:

To print the corresponding values in itemsList for any element in keysList with a value greater than 60, you can use a loop and an if statement.

Step-by-step explanation:

To print the corresponding values in itemsList for any element in keysList with a value greater than 60, you can use a loop to iterate through the keysList. Inside the loop, you can use an if statement to check if the current element is greater than 60. If it is, you can print the corresponding value in itemsList, followed by a semicolon.

Here is an example:

keysList = [32, 105, 101, 35]
itemsList = [10, 20, 30, 40]
for i in range(len(keysList)):
if keysList[i] > 60:
print(itemsList[i], end=';')

This will output: 20;30;

User Buc
by
4.5k points
1 vote

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;

Step-by-step 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.
User RealCheeseLord
by
3.9k points