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
PLS FAST DONT EXPLAIN
Rzqust [24]

Answer:

</head>

Explanation:

8 0
3 years ago
In this assessment, you will design and code a Java console application that validates the data entry of a course code (like IT4
ivolga24 [154]

Answer:

The program is written using jCreator IDE

Comments are used for explanatory purpose

Program starts here

import java.util.*;

public class courecode

{

public static void main(String [] args)

{

 String ccode; // Declare course code as string

 Scanner input = new Scanner(System.in);

 System.out.print("Course code: "); // Prompt user for input

 ccode = input.nextLine();

 boolean flag = true; // Initialize a boolean variable to true

 if(ccode.length() != 6) // Check if length of course code is 6

 {

  System.out.print("Input length must be 6"); //Display message if length of input string is not 6

 }

 else // If length is 6

 {

  for(int i = 0; i<6;i++) //check validity if input string using for loop

  {

   if(i == 0) //Test for first character

   {

    //The following if statement will be executed if the first character is not i or I

    if(ccode.charAt(i) != 'i' && ccode.charAt(i) != 'I')

    {

     System.out.println("Invalid Course Code");

     System.out.println("The course code must start with an i or I");

     flag = false; //Set boolean variable to false

     break;

    }

   }

   else if(i == 1)

   {

    //The following if statement will be executed if the second character is not t or T

    if(ccode.charAt(i) != 't' && ccode.charAt(i) != 'T')

    {

     System.out.println("Invalid Course Code");

     System.out.print("The second letter of the course code must be t or T");

     flag = false; //Set boolean variable to false

     break;

    }

   }

   else

   {

    //The following if statement will be executed if any of the last 4 characters is not an integer

    if(!Character.isDigit(ccode.charAt(i)))

    {

     System.out.println("Invalid Course Code");

     System.out.print("The last 4 characters of the course code must be an integer");

     flag = false; //Set boolean variable to false

     break;

    }

   }

  }  

 }

 //The following statment checks if boolean variable flag is still true

 // If true, then the input course code is valid and the accompanying print statement will be executed

 if(flag)

 {

  System.out.print("The input course code is valid");

 }  

}  

}

Explanation:

Lines marked with // are comments

Check comments (//) for explanation

4 0
3 years ago
How does the Lossy file format reduce the file size?
beks73 [17]

The answer is c. I just took it on apex n that’s what I got lol

3 0
4 years ago
Read 2 more answers
Using hard disk space to temporarily store data or instructions from ram is referred to as the
madreJ [45]
*nix - swap partition
All OS's - swap file[s]
Windows - page file
5 0
4 years ago
The information given to you by your teachers is always accurate and should never be questioned. Please select the best answer f
gavmur [86]

Answer:

im trying to find the answer my self :(

Explanation:

.

3 0
3 years ago
Other questions:
  • Please help i really need to turn this in already
    6·1 answer
  • If I gain a rank and go under the points that the rank coust do I lose the rank
    8·2 answers
  • What are three situations when recursion is the only option available to address problems?
    10·1 answer
  • Arrange the steps in a sequence that you would follow while sorting data in a spreadsheet.
    12·1 answer
  • A _____ is a basic element that refers to the continuous movement of a point along a surface, such as by a pencil or brush a typ
    9·1 answer
  • Write a recursive method that returns the number of 1’s in the binary representation of N. Use the fact that this is equal to th
    9·1 answer
  • Give an example of a class and an example of an object. Describe what a class is, what an object is, and how they are related. U
    6·1 answer
  • There is a population of owls in a forest. In one year there are 20 new owls born and 10 owls die. In this same year, 5 owls ent
    14·1 answer
  • _____ have networked and texted all of their lives with smartphones, tablets, and high-speed Internet.
    8·1 answer
  • DOES ANYONE KNOW COMPUTER SCIENCE?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!