Java. For any element in keysList with a value greater than 100, print the corre
ID: 3860249 • Letter: J
Question
Java.
For any element in keysList with a value greater than 100, print the corresponding value in itemsList, followed by a space. Ex: if keysList = {42, 105, 101, 100} and itemsList = {10, 20, 30, 40}, print:
20 30
Since keysList[1] and keysList[2] have values greater than 100, the values of itemsList[1] and itemsList[2] are printed.
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 = 0;
keysList[0] = 42;
keysList[1] = 105;
keysList[2] = 101;
keysList[3] = 100;
itemsList[0] = 10;
itemsList[1] = 20;
itemsList[2] = 30;
itemsList[3] = 40;
/* Your solution goes here */
System.out.println("");
return;
}
}
Explanation / Answer
ArraysKeyValue.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 = 0;
keysList[0] = 42;
keysList[1] = 105;
keysList[2] = 101;
keysList[3] = 100;
itemsList[0] = 10;
itemsList[1] = 20;
itemsList[2] = 30;
itemsList[3] = 40;
/* Your solution goes here */
for(i=0; i<SIZE_LIST; i++){
if(keysList[i] > 100){
System.out.print(itemsList[i]+" ");
}
}
System.out.println("");
return;
}
}
Output:
20 30
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.