Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Integer arrays groceryItemCosts and daysUntilExpire are read from input, containing the costs and number of days until expired of each grocery item. Initialize variable count

Integer arrays groceryItemCosts and daysUntilExpire are read from input, containing the costs and number of days until expired of each grocery item. Initialize variable count with 0. For each grocery item, increment count if a grocery item meets both of the following conditions:
Cost is an even integer.
Number of days until expired is greater than 20.
Lastly, output count followed by a newline.
Ex: For the input:
271252118
1527101724
then the output is:
2
import java.util.Scanner;
public class CombineArrays {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
final int NUM_VALS =5;
int[] groceryItemCosts = new int[NUM_VALS];
int[] daysUntilExpire = new int[NUM_VALS];
int i;
int count;
for (i =0; i < NUM_VALS; ++i){
groceryItemCosts[i]= scnr.nextInt();
}
for (i =0; i < NUM_VALS; ++i){
daysUntilExpire[i]= scnr.nextInt();
}
/* Your code goes here */
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago