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
Explain three applications of computers and information systems in the daily life of a college student.
Savatey [412]

Answer:

Drawing tools, spreadsheets, Audio, Video lectures, and PowerPoint presentations, etc.

5 0
2 years ago
What tells the hardware what to do and how to do it?
oksano4ka [1.4K]

Answer:

I think its CPU

Explanation:

8 0
3 years ago
In a database, data is stored in spreadsheets which have rows and columns.
Tcecarenko [31]
The answer is A. True.
5 0
3 years ago
Which of the following items will you use to store your digital portfolio? A. notebook B. file C. flash drive D. folder
AnnZ [28]

Answer:

C)

Explanation:

that what i would use

3 0
3 years ago
Read 2 more answers
Whenever they are passed as parameters to a function, the IO classes istream and ostream must be passed using a pass-by-referenc
morpeh [17]

Answer:

b. TRUE

Explanation:

Whenever they are passed as parameters to a function, the IO classes istream and ostream must be passed using a pass-by-reference parameter passing scheme.

This is because , assuming a pass by value semantics would require us to copy the value of the istream or ostream object which would be meaningless. In fact these objects don't even have a copy constructor at all. So such objects are always passed by reference.

7 0
3 years ago
Other questions:
  • What makes Group Policy such a powerful tool is its ability to enable security administrators to:_________.
    8·1 answer
  • This toolbar can be used to change the way the text in your presentation looks. Drawing
    5·2 answers
  • . Write a recursive function names factorial to compute the factorial of the parameter. Also write the main function, where you
    15·1 answer
  • When adapting graphs for slides,
    6·1 answer
  • What is the point of completing a value assessment while searching for a career
    11·1 answer
  • Which of these is a major mobile game developer?
    9·1 answer
  • What is the unit of information called when a network adapter adds the source and destination mac address to the segment of data
    15·1 answer
  • Bluetooth 5 allows data to be transferred between two devices at a rate of
    8·1 answer
  • Wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww!
    7·1 answer
  • HELP ME PASS!
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!