1answer.
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
Brrunno [24]
3 years ago
5

Write a static method named evenNumbers that accepts a string of text as a parameter. Assume that the text is a series of intege

rs, and process this text and report various statistics about the integers. Report the total number of numbers, the sum of the numbers, the total count of even numbers and the percent of even numbers. For example, if the string is the following: "5 7 2 8 9 10 12 98 7 14 20 22"
Computers and Technology
2 answers:
Allisa [31]3 years ago
8 0

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Import input/output and utility libraries

import java.io.*;

import java.util.*;

Declare class/

public class Numbers {

// Main method goes here

public static void main(String[] args) throws FileNotFoundException

{

// Read input from text file evenFile.txt; Assume file name is evenFile.txt

Scanner input = new Scanner(new File("evenFile.txt"));

// Call static method here

evenNumbers(input);

}

// Static method evenNumbers begins here

public static void evenNumbers(Scanner input)

{

// Declare and initialise Variables

String Nums = input.nextLine(); // Read all number in txt file

Scanner numbers = new Scanner (Nums);

int count = 0; // Number count

int evens = 0; // Even count

int sum = 0; // Summation of numbers

// Check if number is integer. If yes, continue the below operations

while (numbers.hasNextInt())

{

int num = numbers.nextInt();

count++;

sum = sum + num;

if(num % 2 == 0) // check for even

{

evens++;

}

}

System.out.println("Total numbers= " + count); // Print total number

System.out.println("Sum of numbers = " + sum); // Print summation of numbers

System.out.println("Total evens = " + evens); // Print total even

//Calculate and print percentage of even number

double percent = ((double)evens/count)*100.0);

System.out.println("Percent of even number = " +percent);

}

}

// End of program

r-ruslan [8.4K]3 years ago
8 0

Answer:

The output must follow this:

Total numbers = 12

Sum of numbers = 214

Total evens = 8

Percent evens = 66.66666666666667

Therefore, the method produce the total output of:

Total output=12

Sum of numbers= 12

Total events= 8

Percent even= 66.66666412353516

Explanation:

public class StringArray {

public static void evenNumbers(String str)

{

String[] parts = str.split(" ");

int[] ints = new int[parts.length];

for (int i = 0; i < parts.length; i++) {

ints[i] = Integer.parseInt(parts[i]);

}

System.out.println("Total numbers ="+ints.length);

int sum=0;

for (int i = 0; i < ints.length; i++)

sum+=ints[i];

System.out.println("Sum of numbers ="+ints.length);

int count=0;

for (int i = 0; i < ints.length; i++)

{

if(ints[i]%2==0)

count++;

}

System.out.println("Total evens="+count);

float l=ints.length;

double per=(count*100)/l;

System.out.println("Percent evens="+per);

}

public static void main(String[] args) {

String str="5 7 2 8 9 10 12 98 7 14 20 22";

evenNumbers(str);

}

}

You might be interested in
The maximum number of characters that a cell can contain is
lina2011 [118]
The answer is:

32,767
6 0
3 years ago
Read 2 more answers
Which types of scenarios would the NETWORKDAYS function help calculate? Check all that apply.
Luden [163]

Answer:

The answer is A,B,D.

Explanation:

The answers: days of vacation time left

days of school left in the year & years of service someone performed

were correct on edgenuity. (IG:ixv.mona)

5 0
3 years ago
A fast way to add up a column of numbers is to click in the cell below the numbers and then: Click Subtotals on the Data menu. V
Art [367]

Answer:

Click the AutoSum button on the Standard toolbar, then press ENTER

Explanation:

Excel offers a range of options to perform various mathematical operations. When numeric values are being inputted into cells, either columns or rows, the AutoSum function which is located in the home Taskbar allows for a very fast addition of the total values in the column or rows. Once the cell after the last cell value is selected, the AutoSum function is selected and the ENTER button is pressed, this will use the sum function of excel to quickly provide the total sum of all the values in the column.

3 0
3 years ago
Read 2 more answers
Which organization has published more than 300 Web standards, and encourages manufacturers to follow these standards, many of wh
jek_recluse [69]

Answer:

c

Explanation:

6 0
4 years ago
What are the different options in a page layout feature ? Select three options
Sever21 [200]

Answer:

Half Center Right Left, theres four

Explanation:

5 0
3 years ago
Other questions:
  • Are there protections for people in terms of what data can be collected by different sites?
    10·1 answer
  • How i can connect to internet automatically when i switch on my computer?
    8·1 answer
  • How to use javascript libraries in javascript code?
    9·1 answer
  • Match the spreadsheet features with their respective descriptions.
    7·2 answers
  • What type of engineer works on cleaning up oil spills?
    8·2 answers
  • Plymouth Colony was originally founded by a group of people called Pilgrims. Since Plymouth did not have an official charter fro
    15·1 answer
  • There are many modes of remote visual communication. which is the most common mode
    5·1 answer
  • Proxy download for school
    15·2 answers
  • The first page of a website is what?​
    5·2 answers
  • What is your favorite song? mine is "In the final"
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!