Ask Question
20 July, 10:45

For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. Ex: If keysList = {32, 105, 101, 35} and itemsList = {10, 20, 30, 40}, print: 20 30

JAVA

import java. util. Scanner;

public class ArraysKeyValue {

public static void main (String [] args) {

final int SIZE_LIST = 4;

int[] keysList = new int[SIZE_LIST];

int[] itemsList = new int[SIZE_LIST];

int i;

keysList[0] = 13;

keysList[1] = 47;

keysList[2] = 71;

keysList[3] = 59;

itemsList[0] = 12;

itemsList[1] = 36;

itemsList[2] = 72;

itemsList[3] = 54;

+5
Answers (1)
  1. 20 July, 14:20
    0
    import java. util. Scanner; / /mentioned in the question.

    public class ArraysKeyValue { / /mentioned in the question.

    public static void main (String [] args) { / /mentioned in the question.

    final int SIZE_LIST = 4; / /mentioned in the question.

    int[] keysList = new int[SIZE_LIST]; / /mentioned in the question.

    int[] itemsList = new int[SIZE_LIST]; / /mentioned in the question.

    int i; / /mentioned in the question.

    keysList[0] = 13; / /mentioned in the question.

    keysList[1] = 47; / /mentioned in the question.

    keysList[2] = 71; / /mentioned in the question.

    keysList[3] = 59; / /mentioned in the question.

    itemsList[0] = 12; / /mentioned in the question.

    itemsList[1] = 36; / /mentioned in the question.

    itemsList[2] = 72; / /mentioned in the question.

    itemsList[3] = 54; //mentioned in the question.

    / / other line to complete the solution is as follows--

    for (i=0; i< (keysList. length); i++) / /Loop to access all the element of keysList array variable.

    {/ / open for loop braces

    if (keysList[i]>50) / / compare the value of keysList array variable with 50.

    System. out. println (itemsList[i]); / / print the value

    }/ / close for loop braces.

    }/ / close main function braces.

    } / /close the class braces.

    Output:

    72

    54

    Explanation:

    In the solution part--

    One loop is placed which moves from 0 to (size-1) of the 'keyslist' array. Then the 'if' statement is used to check the element of 'keyslist' array, which is greater than 50 or not. If it is greater, then print the element of item_list array of 'i' index which is also the index of greater value of keyslist array element.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. Ex: If keysList ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers