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...
Program P1 1) integer A, B; 2) input (A); 3) while (A > 0) 4) {...
Program P1 1) integer A, B; 2) input (A); 3) while (A > 0) 4) { 5) B = 1; 6) if (A < 10) 7) B = 0; 8) if (A < 20 or A > 25) 9) B = A * B; 10) else 11) B = A + B; 12) output (A, B); 13) input (A); 14) } 15) output (“Program ends.”); 16) end; T = {t1=<1>, t2=<33>, t3=<‐1>} or T = {t1=, t2=, t3=} 1. What...
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...
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...
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.
The following page-reference string: 1, 2, 4, 3, 2, 5, 4, 2, 4, 2, 1, 3,...
The following page-reference string: 1, 2, 4, 3, 2, 5, 4, 2, 4, 2, 1, 3, 2, 3, 1, 3, 6, 1, 6, 4. Main memory with 3 frames of 1 kilobyte available and they are all initially empty. Complete a figure, similar to Figure 8.14(in the slides or textbook), showing the frame allocation for each of the following page replacement policies: a. Optimal b. Least recently used c. First-in-first-out Then, find the relative performance of each policy with respect...
********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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT