answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kvv77
26 days ago
8

For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. Ex: I

f 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;
Computers and Technology
1 answer:
ivann1987 [1K]26 days ago
5 0

Answer:

import java.util.Scanner;  //as referenced in the prompt.

public class ArraysKeyValue {  //as mentioned in the prompt.

public static void main (String [] args) {  //as stated in the prompt.

final int SIZE_LIST = 4; //as indicated in the prompt.

int[] keysList = new int[SIZE_LIST]; //as specified in the prompt.

int[] itemsList = new int[SIZE_LIST]; //as outlined in the prompt.

int i; //as identified in the prompt.

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

keysList[1] = 47; //as stated in the prompt.

keysList[2] = 71; //as described in the prompt.

keysList[3] = 59; //as referenced in the prompt.

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

itemsList[1] = 36; //as stated in the prompt.

itemsList[2] = 72; //as specified in the prompt.

itemsList[3] = 54;//as indicated in the prompt.

// additional line needed to finalize the solution is as follows--

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

    {// open for loop braces

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

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

   }// close for loop braces.

}//  close main function braces.

} //close class braces.

Output:

72

54

Explanation:

In the resolution section--

  1. A single loop is engaged that iterates from 0 to (size-1) of the 'keyslist' array.
  2. The 'if' statement checks whether the 'keyslist' array's element exceeds 50 or not.
  3. If it does, the respective 'i' indexed item from the item_list array is printed as well, which corresponds to the higher value of the keyslist array element.

You might be interested in
Write a program using the standard library I/O functions (fopen, fread, fwrite, fclose, ferror, feof, and fflush) to read a text
amid [951]

Answer:

Refer to the explanation

Explanation:

#include <stdio.h>

#include <stdlib.h>

#include<string.h>

int main(int argc, char *argv[])

{

FILE *fr,*fr1,*fr3; /* declare the file pointer */

char filename[256];

char search[256];

char line[256];

int count=0;

char replace[256];

printf("Enter FileName: "); // ask for filename

scanf("%s",filename);

fr3 = fopen (filename, "r");

if(ferror(fr3)) //check for any error assosicated to file

{

fprintf(stderr, "Error in file"); // print error in stderr

printf("Error");

}

printf("Input file data is");

while(!feof(fr3)) // checking end of file condition

{ //printf("inside");

fgets(line,256,fr3);

printf("%s",line);

}

printf("\nEnter String to search: "); //ask for string to search

scanf("%s",search);

printf("Enter string with whom you want to replace: "); //ask for string with whom you want to replace one time

scanf("%s",replace);

fr = fopen (filename, "r"); // open first file in read mode

fr1 = fopen ("output.txt", "w"); //open second file in write mode

if(ferror(fr)) //check for any error assosicated to file

{

fprintf(stderr, "Error in file"); // print error in stderr

printf("Error");

}

while(!feof(fr)) // checking end of file condition

{ //printf("inside");

fgets(line,256,fr);

int r=stringCompare(line,search); // comparing every string and search string

// printf("%d",r);

if(r==1 && count==0)

{

fwrite(replace, 1, sizeof(replace), fr1 ); // writing string to file.

printf("%s\n",replace);

count++;

}

else{

printf("%s",line);

fwrite(line, 1, sizeof(line), fr1 );

}}

printf("\n");

fflush(fr1); // it will flush any unwanted string in stream buffer

fflush(fr);

fflush(fr3);

fclose(fr); //closing file after processing. It is important step

fclose(fr1);

fclose(fr3);

system("PAUSE");

return 0;

}

// Compare method which is comparing charaacter by character

int stringCompare(char str1[],char str2[]){

int i=0,flag=0;

while(str1[i]!='\0' && str2[i]!='\0'){

if(str1[i]!=str2[i]){

flag=1;

break;

}

i++;

}

if (flag==0 && (str1[i]=='\0' || str2[i]=='\0'))

return 1;

else

return 0;

}

7 0
25 days ago
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Els
Natasha_Volkova [1026]
Here's a C code snippet: #include <stdio.h> int main() { int year; printf("enter year:"); scanf("%d",&year); if(year>=2101) { printf("Distant future"); } else if(year>=2001&&year<=2100) { printf("21st century"); } else if(year>=1901&&year<=2000) { printf("20th century"); } else if(year<=1900) { printf("Long ago"); } return 0;} Output: enter year:2018 21st century. </stdio.h>
7 0
16 days ago
Read 2 more answers
Su now wants to highlight several inventors in her presentation, so she decides to use the underline color option.
Harlamova29_29 [1022]

Answer:

1. The home tab

2. Font group

3. The small arrow at the bottom right of the font command group.

4. Under "Font" heading (then "All text" subheading)

Explanation:

This explanation will guide Su in completing her task.

1. Navigate to the home tab;

2. From the home tab, Su will access a variety of command groups, but for her needs, she requires the Font command group.

3. A tiny arrow can be found at the bottom left of the font command group section; clicking it will unveil the font dialogue.

4. Within the font dialogue, there are two headings. The "font" heading and the "character spacing" heading.

For her purposes, she must focus on the "Font" heading, which includes various subheadings. To reach the underline color option, she needs to select the "All text" subheading.

Refer to the attached image for guidance.

7 0
1 month ago
To be a successful computer systems engineer, you must be proficient in programming languages and operating systems. Similarly,
maria [1035]

In summary, the skills listed are referred to as Technical capabilities. These capabilities encompass the Knowledge and skillset required to execute specific tasks. Meanwhile, Soft skills are equally vital, as they pertain to the capability of effectively engaging and communicating with others.

6 0
17 days ago
Read 2 more answers
Write an expression that will print "Dollar or more" if the value of num_cents is at least a dollar (100 cents is a dollar). Sam
amid [951]
num_cents = 109 if num_cents >= 100: print('Dollar or more') else: print('not a dollar')
7 0
25 days ago
Other questions:
  • When using the Python shell and code block, what triggers the interpreter to begin evaluating a block of code
    14·1 answer
  • Light travels at 3 × 108 meters per second. A light-year is the distance a light beam travels in one year.Write a PYTHON program
    14·1 answer
  • Splunk In most production environments, _______ will be used as the source of data input?
    12·1 answer
  • Some early computers protected the operating system by placing it in a memory partition that could not be modified by either the
    5·1 answer
  • Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 3
    15·1 answer
  • The president of the company wants a list of all orders ever taken. He wants to see the customer name, the last name of the empl
    15·1 answer
  • Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only
    9·2 answers
  • An application specifies a requirement of 200 GB to host a database and other files. It also specifies that the storage environm
    12·1 answer
  • PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
    6·1 answer
  • JAVA Write a program that first asks the user to type a letter grade and then translates the letter grade into a number grade. L
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!