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
choli [55]
3 years ago
12

Write an application that will input four positive integers from the user. The program should print out the largest and smallest

number. It should print how many of the numbers are even and how many are odd. It should print how many of the numbers are one digit and how many of the numbers are two digit.It should print out the sum of all even numbers and the sum of all odd numbers. It should print out the sum of all one digit numbers and the sum of all two digit numbers.You do not need to do any error checking to make sure that the numbers are positive or one or two digit. You may not use arrays or loops for this lab.
Computers and Technology
1 answer:
ZanzabumX [31]3 years ago
4 0

Answer:

The solution is given using Java

Explanation:

import java.util.Scanner;

public class Numbers {

  public static void main(String[] args) {

      // Create scanner object to help take user input

      Scanner sc = new Scanner(System.in);

     

      //Variables to store different sums

      int sumEven=0,sumOdd=0,sumOneDigit=0,sumTwoDigit=0;

     

      //Prompt message to user and store it in variables

      System.out.println("Enter four positive integers: ");

      int num1 = sc.nextInt();

      int num2 = sc.nextInt();

      int num3 = sc.nextInt();

      int num4 = sc.nextInt();

     

      //Find and print Largest number

      int largest = num1;

      if(num2>largest)

          largest=num2;

      if(num3>largest)

          largest=num3;

      if(num4>largest)

          largest=num4;

      System.out.println("The largest number is: "+largest);

     

      //Find and print smallest number

              int smallest = num1;

              if(num2<smallest)

                  smallest=num2;

              if(num3<smallest)

                  smallest=num3;

              if(num4<smallest)

                  smallest=num4;

              System.out.println("The smallest number is: "+smallest);

             

      //Count and print number of even and odd numbers

      //Also find sum of even and odd numbers

      int oddCount=0,evenCount=0;

      if(num1%2 == 0) {

          evenCount++;

          sumEven = sumEven + num1;

      }

      else {

          oddCount++;

          sumOdd = sumOdd + num1;

      }

     

      if(num2%2 == 0){

          evenCount++;

          sumEven = sumEven + num2;

      }

      else{

          oddCount++;

          sumOdd = sumOdd + num2;

      }

     

      if(num3%2 == 0){

          evenCount++;

          sumEven = sumEven + num3;

      }

      else{

          oddCount++;

          sumOdd = sumOdd + num3;

      }

     

      if(num4%2 == 0){

          evenCount++;

          sumEven = sumEven + num4;

      }

      else{

          oddCount++;

          sumOdd = sumOdd + num4;

      }

     

      System.out.println("Number of even numbers: "+evenCount);

      System.out.println("Number of odd numbers: "+oddCount);

     

      //Count and print number of one digit and two digit numbers

      //Also find sum of even and odd numbers

      int oneDigitCount=0,twoDigitCount=0;

      if((Integer.toString(num1)).length()==1) {

          oneDigitCount++;

          sumOneDigit = sumOneDigit +num1;

      }

      else if((Integer.toString(num1)).length()==2) {

          twoDigitCount++;

          sumTwoDigit = sumTwoDigit + num1;

      }

         

      if((Integer.toString(num2)).length()==1){

          oneDigitCount++;

          sumOneDigit = sumOneDigit +num2;

      }

      else if((Integer.toString(num2)).length()==2){

          twoDigitCount++;

          sumTwoDigit = sumTwoDigit + num2;

      }

     

      if((Integer.toString(num3)).length()==1){

          oneDigitCount++;

          sumOneDigit = sumOneDigit +num3;

      }

      else if((Integer.toString(num3)).length()==2){

          twoDigitCount++;

          sumTwoDigit = sumTwoDigit + num3;

      }

     

      if((Integer.toString(num4)).length()==1){

          oneDigitCount++;

          sumOneDigit = sumOneDigit +num4;

      }

      else if((Integer.toString(num4)).length()==2){

          twoDigitCount++;

          sumTwoDigit = sumTwoDigit + num4;

      }

     

      //Print the results

      System.out.println("Number of one digit numbers: "+oneDigitCount);

      System.out.println("Number of two digit numbers: "+twoDigitCount);

     

      System.out.println("Sum of even numbers: "+sumEven);

      System.out.println("Sum of odd numbers: "+sumOdd);

      System.out.println("Sum of one digit numbers: "+sumOneDigit);

      System.out.println("Sum of two digit numbers: "+sumTwoDigit);

  }

}

You might be interested in
Which statement describes how to insert the IF, COUNTIF, or SUM function into a cell?
aleksley [76]

Answer:

Type an = sign in the cell, followed by the name of the function and the relevant arguments.

Explanation:

Microsoft Excel is a software application or program designed and developed by Microsoft Inc., for analyzing and visualizing spreadsheet documents. There are different types of functions used in Microsoft Excel to perform specific tasks and these includes;

1. VLOOKUP function: it's an Excel function that avails end users the ability to lookup data in a table organized vertically. Thus, it's typically used for searching values in a column.

2. SUMIF function: it is an Excel function to sum cells that meet criteria such as text, dates and numbers. This function can be used with the following logical operators; <, >, and =.

3. COUNT function: it's an Excel function to find the total number of entries in a column. For example, to count the number of entries in B1:B15; COUNT(B2:B15).

4. IF function: runs a logical test and returns one value for a TRUE result, and another for a FALSE result. For example, to fail scores that are below 40; IF (A1 < 40, "Fail", "Pass").

5. HLOOKUP function: it's an Excel function that avails end users the ability to lookup data in a table organized horizontally. Thus, it's typically used for searching values in a column.

In Microsoft Excel, to insert the IF, COUNTIF, or SUM function into a cell, you should type an equal to (=) sign in the cell, followed by the name of the particular function and the relevant arguments.

For example, to use the SUMIF function, you should type; =SUMIF(A2:B5, "Peter", C1:C9).

7 0
3 years ago
Which of the following represent emerging classes of application software? Check all of the boxes that apply.
soldi70 [24.7K]
Word processing and databases are the most common type of application software. In this case, application software, often called productivity programs, are programs designed to specifically attain specific tasks such as creating documents, databases, sending email, designing graphics and even playing games. A mobile app is also an emerging type of application software designed to run on portable devices like mobiles and PDAs. To some extent, email software is an application software since it can also be distinguished on the basis of usage.






7 0
4 years ago
Read 3 more answers
Where does change management play a major role in transforming a client
nevsk [136]

To manage a modern IT environment characterized by hybrid complexity and exponential data growth — and to make that same IT a driver of growth and innovation for the business — you need to build intelligence into every layer of your infrastructure.

3 0
3 years ago
Identify a true statement about heuristics: a. They are more complicated than algorithms. b. Unlike algorithms, they do not perm
STatiana [176]

Answer:

The appropriate alternative is Option d.

Explanation:

  • Heuristic also seems to be essentially a methodology that solves numerous major issues in an even cheaper manner. It requires less effort than those of the traditional techniques. It's providing accurate solutions. It has a broader potential in the treatment of computer engineering. It is already being shown in quantum computing.
  • Mathematical implementations also contribute significantly to heuristics. This could make concessions on the component of optimal performance. It can also make concessions on the degree of consistency. It helps to achieve international headquarters at quite a quicker speed.

The latter decisions made are not connected to the conditions. So the above comment is correct.

4 0
3 years ago
onsider the following program: Peform a total of six exercises. Select one exercise from each of the following areas: hips and l
Leviafan [203]

Answer:

Beginner

Explanation:

A program like this is ideal for a beginning exerciser due to the high number of repetitions and the sets are not much.

Cheers

3 0
3 years ago
Other questions:
  • Which of the following assignment statements contains a LOGICAL error? I multiply two numbers when they need to be added I write
    9·1 answer
  • Do most facebook and twitter users access the platform from their personal computers?
    6·2 answers
  • Which key removes all data from an active cell with one click? A. Esc B. Delete C. Tab D. F2
    9·2 answers
  • 1.Context clues can be used to determine the ________of an unfamiliar word
    5·2 answers
  • When adding a background to a Web page, it can be _____. a. a solid color b. a fill effect c. an image d. all of the above
    12·1 answer
  • Lol WAKE UP!!! and get ready to answer my questions.
    12·1 answer
  • First person to make me laugh will get brainliest.​
    10·2 answers
  • Your organization has 20 employees who need an accounting software update installed. Due to a miscommunication, the purchaser on
    6·1 answer
  • a matched-pairs t-test is not an appropriate way to analyze data consisting of which of the following?
    11·1 answer
  • You find a picture of a famous department store online that would be great to include in a project of yours. What should you do
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!