Question
this is java

Write a test class that accepts 25 values from keyboard. All odd values must be added. All over values must be multiplied. Di
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution: Java code has been given below along with the output. Comments have been placed in the code to depict the functionality of the different statements.

import java.util.*;
//class definition
//will include the main 
public class TestA{

        public static void main(String args[])
        {

                //variable to store value 25 
                int counter=25;
                //variable to store the odd numbers sum
                int sum =0;
                //variable to store the even numbers multiplication
                int mul =1;

                //Scanner class to read user input
                Scanner reader = new Scanner(System.in);
                System.out.println("Enter 25 numbers");
                for (int i=0;i<25;i++)
                {
                        int x = reader.nextInt();

                        //check even or odd 
                        if (x%2==0)
                        {
                                mul = mul * x;
                        }
                        else 
                        {
                                sum = sum + x;
                        }

                }

                //Print totals
                System.out.println("******* Accumulated Totals ******");
                System.out.println("Even Numbers: "+ mul);
                System.out.println("Odd Numbers: "+ sum);
        }


}

Output:

java TestA
Enter 25 numbers
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
******* Accumulated Totals ******
Even Numbers: 32768
Odd Numbers: 45

Add a comment
Know the answer?
Add Answer to:
this is java Write a test class that accepts 25 values from keyboard. All odd values...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question: Write a java class to accept data from user via keyboard for (1) User name...

    Question: Write a java class to accept data from user via keyboard for (1) User name (2) three integer values,then calculate sum& average. O/P in DOS with one(1) print method for all I/O data. Line l Line 2 Line 4: Line 6 Line 7 Line 8

  • Write an application in java that accepts any number of String values from a user until...

    Write an application in java that accepts any number of String values from a user until they enter zzz or have entered 15 strings, and display them in ascending order.

  • Solve it by JAVA please. Now, write a class named InputSplitter. This class will take input...

    Solve it by JAVA please. Now, write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split the incoming tokens into integers, floating point numbers, and strings. The incoming tokens will be added to one of three accumulators which start out at zero, and which keep a running total. Thus, the class will have an accumulator for integers. It starts out with the value zero. Every time another integer is read in, it...

  • Write a C++ program that does the following : 1. Accepts array size from the keyboard....

    Write a C++ program that does the following : 1. Accepts array size from the keyboard. The size must be positive integer that is >= 5 and <= 15 inclusive . 2. Use the size from step 1 in order to create an integer array. Populate the created array with random integer values between 10 and 200. 3. Display the generated array. 4. Write a recursive function that displays the array in reverse order . 5. Write a recursive function...

  • Write a Java class that examines a single character input from the keyboard. Follow this dialog...

    Write a Java class that examines a single character input from the keyboard. Follow this dialog to guide your coding: Type a single character and press Enter: m Digit: No Letter: Yes Lowercase: Yes Toggle case: M Note: There is no "next" method of the Scanner class to obtain input from the keyboard of data type char. It simply doesn't exist so you need a workaround. Store the end-user input into a String variable; then extract the first character using...

  • Write a Java console application that reads a string from the keyboard and tests whether it...

    Write a Java console application that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is NOT valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). You can use: String monthPart = inputDate.substring(0, 2); int month =...

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • The Scanner class in Java has several methods for reading values entered from the keyboard. The...

    The Scanner class in Java has several methods for reading values entered from the keyboard. The methods include next, nextInt, and nextLine. Which of the following statements is INCORRECT about the methods? Pick the best applicable answer Assuming that the user has typed: Hello World! If you invoke the next method for the first time, it will return the string "Hello", and if you invoked next method for the second time, it will return the string "World!" If you want...

  • Write a Java program that reads 10 integers from the keyboard and outputs all the pairs...

    Write a Java program that reads 10 integers from the keyboard and outputs all the pairs whose sum is 30 .

  • Part A Write a Java program that reads an integer n from the keyboard and loops...

    Part A Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised. Part B Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied.   Will give thumbs up...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT