Question

In: Computer Science

Input Format 4 1 2 3 4 Constraints there will be no more than 50 input...

Input Format

4 1 2 3 4

Constraints

there will be no more than 50 input numbers.

Output Format

Odd: 2 Even: 2 Divisible by 7: 0 Average: 250

Sample Input 0

4
1 2 3 4

Sample Output 0

Odd: 2
Even: 2
Divisible by 7: 0
Average: 250

import java.io.*;

import java.math.*;

import java.security.*;

import java.text.*;

import java.util.*;

import java.util.concurrent.*;

import java.util.regex.*;



public class Solution {

    public static void main(String[] args) throws IOException {

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(bufferedReader.readLine().trim());

        String[] arrTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");

        List<Integer> arr = new ArrayList<>();

        for (int i = 0; i < n; i++) {

            int arrItem = Integer.parseInt(arrTemp[i]);

            arr.add(arrItem);

        }

        // You now have an array of integers called arr. You should process the array to achieve the results.

        // note that you can refer to items in arr using standard Java array notation

        // arr[0] will give you the item at location 0 in this array

        // Write your code here

        bufferedReader.close();

    }

}

Solutions

Expert Solution

CODE :

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(bufferedReader.readLine().trim());

String[] arrTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");

List<Integer> arr = new ArrayList<>();

for (int i = 0; i < n; i++) {
int arrItem = Integer.parseInt(arrTemp[i]);
arr.add(arrItem);
}

// You now have an array of integers called arr. You should process the array to achieve the results.

// note that you can refer to items in arr using standard Java array notation

// arr[0] will give you the item at location 0 in this array

int e = 0, o = 0, s = 0, d = 0;
for(int i = 0; i < arr.size(); i++)
{
if(arr.get(i) % 2 == 0)
{
e++;
}
if(arr.get(i) % 2 != 0)
{
o++;
}
if(arr.get(i) % 7 == 0)
{
d++;
}
s += arr.get(i);
}
System.out.println(s);
System.out.println("Odd : " + o);
System.out.println("Even : " + e);
System.out.println("Divisible by 7 : " + d);
System.out.println("Average : " + (float)s/n);
bufferedReader.close();
}
}
OUTPUT :


Related Solutions

Year 1 $50 Year 2-6: 4% more than the previous year Year 7 to forever: 1%...
Year 1 $50 Year 2-6: 4% more than the previous year Year 7 to forever: 1% more then the previous year At 9% APR, what is the present value infinity 978.24 1027.15 1,078.51 1,132.43
Simple evaluation of the design criteria of digital camera: 1- visibility: 2- feedback: 3- constraints: 4-...
Simple evaluation of the design criteria of digital camera: 1- visibility: 2- feedback: 3- constraints: 4- consistency: 5- affordance:
Submit a paper which is 2-3 pages in length (no more than 4-pages), exclusive of the...
Submit a paper which is 2-3 pages in length (no more than 4-pages), exclusive of the reference page. The paper should be double spaced in Times New Roman (or its equivalent) font which is no greater than 12 points in size. The paper should cite at least three sources in APA format. One source can be your textbook. In this paper, please discuss the following case study. In doing so, explain your approach to the problem, support your approach with...
(2)   In the United States, more than 50% of banks have less than $100 million in...
(2)   In the United States, more than 50% of banks have less than $100 million in assets: T or F? (3)   In 1980, there were 14,404 commercial banks in the United States, but now there are 5,116 in 2020: T or F? (4)   The U.S. banking industry is highly concentrated compared with other industries in the United States or compared with the banking industry in other countries: T or F? (5)   The U.S. banking industry is one of the most...
SE-FamilySize 1 1 4 3 2 4 2 3 4 2 4 1 4 2 2...
SE-FamilySize 1 1 4 3 2 4 2 3 4 2 4 1 4 2 2 4 5 4 5 4 4 2 4 3 1 2 3 5 5 5 Make a confidence interval. Be sure you show all the steps you took. Include a screen shot of any applet you used in your calculations. 2. Choose a confidence level (1 – α). 3. What is xbar? 4. What is s? 5. What is t? (Show a screen shot...
Someone gets more than 8 hours of sleep 50 percent of the time, less than 3...
Someone gets more than 8 hours of sleep 50 percent of the time, less than 3 hours 30 percent of the time, and 3-8 hours (inclusive) 20 percent of the time. when they sleep more than 8 hours, forty percent of the time they score really well. when they get less than 3 hours, 20 percent of the time they score really well. when they get 3-8 hours inclusive they score really well 40 percent of the time. what is...
In no more than 3-4 sentences, respond to the following: Provide a null hypothesis and an...
In no more than 3-4 sentences, respond to the following: Provide a null hypothesis and an alternative hypothesis for a research experiment that utilizes the one-tailed test or the two-tailed test. Be sure to clearly specify which one you selected.
********NEEDS TO BE IN EASSAY TYPE FORMAT AND NO MORE THAN 500 WORDS !!! i will...
********NEEDS TO BE IN EASSAY TYPE FORMAT AND NO MORE THAN 500 WORDS !!! i will give a thumbs up... also no plagerism we submit this through a database!!!!********* Develop an essay response of no more than 500 words to the following: (1) Concept of balancing the "me" with the "we;" (2) Ways self-leadership can be applied to personal problems, and thus personal development; (3) Why should a MBA student be concerned with these topics? (4) How does the outcome...
Submit a written paper which is 3-4 pages in length (no more than 4-pages), exclusive of...
Submit a written paper which is 3-4 pages in length (no more than 4-pages), exclusive of the reference page. Your paper should be double spaced in Times New Roman (or its equivalent) font, which is no greater than 12 points in size. The paper should cite at least three sources in APA format. One source can be your textbook. Please describe the circumstances of the following case study and recommend a course of action. Explain your approach to the problem,...
MONTH   ZEMIN CORP.   MARKET 1 7% 4% 2 2% 1% 3 2% 2% 4 -3% -1%...
MONTH   ZEMIN CORP.   MARKET 1 7% 4% 2 2% 1% 3 2% 2% 4 -3% -1% 5 4% 2% 6   2% 3% a. Given the​ holding-period returns shown above, compute the average returns and the standard deviations for the Zemin Corporation and for the market. b. If​ Zemin's beta is 1.04 and the​ risk-free rate is 9 ​percent, what would be an appropriate required return for an investor owning​ Zemin? ​(​Note: Because the returns of Zemin Corporation are based on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT