Ask Question
28 July, 15:59

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;

+2
Answers (1)
  1. 28 July, 16:24
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers