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
What would you use to see what network adapters are installed in your windows computer?
Lesechka [4]
I wouldn't see anything, because my computer does not use any network adaptors.
6 0
3 years ago
What does the format painter button in excel do
wlad13 [49]
The format painter button in excel copies formatting from one place and it applies it to another
7 0
4 years ago
There are well-known classes of problems that are intractably difficult for computers, and other classes that are provably undec
Wittaler [7]
No. It is not impossible to understand and make this algorithm a success. It may only take a longer duration to reach success but it does not that it is impossible. Problems may become more difficult to understand and debug but there is enough time, duration, resources and support, the algorithm can be developed.
4 0
3 years ago
Brendan is examining a report using the Design view. Which section in the Design view is going to appear only once on the first
goldenfox [79]

Report header section is the section in the Design view is going to appear only once on the first page and could contain logos and title information.

<u>Explanation:</u>

In the Design view, the Create tab is used to create a report within a simple click. Report Wizard is also used in creating reports with various options.

Once you started creating a report, you will notice that it consists of various sections. You have to decide which data used in each section.

Report Header Section will appear at the first page's top also only once throughout the report creation. It consists of contents such as Logo, Report title and Current Date.

3 0
4 years ago
Is technology science? I mean, I think it is... uh, why am I so paranoid about this project.
STALIN [3.7K]

Answer:

i ..d..k do something ez

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
    15·1 answer
  • Lin is booting up his computer, and during the boot process, the computer powers down. After several unsuccessful attempts to bo
    10·1 answer
  • A minor with prior convictions of Minor in Possession (MIP) who is charged with a subsequent MIP may be penalized with a jail se
    15·2 answers
  • It is always safe to enter personal information into a pop-up window. true or false.
    13·1 answer
  • The internet is owned and run by the us government. a) true b) false
    12·2 answers
  • In most operating systems what is running application called?
    5·1 answer
  • First Person Who Answers Fast As Possible Will Be Marked As Brainiest ​
    12·1 answer
  • Which two characteristics of the matter change?
    14·1 answer
  • As a student, why do you need to know and follow the steps printing a <br><br>document?​
    6·2 answers
  • what are some steps Hector could have taken to ensure that his photographs were not ruined near the end of the shoot?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!