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
How do you code to find the surface area 6 s2, volume s3 in python
Nana76 [90]

Answer: you code to find the surface area 6 s2, volume s3 in python

Explanation:if you dont code the surface area 6 s2, volume s3 in python then you  cant code

4 0
3 years ago
before Katie turns in the paper she typed she wants a peer to review it and give her feedback Katie uses her all in one printer
masha68 [24]

It is an input and an output. The scanner scans the paper which is the input ,and the output is when the printer prints the paper.

3 0
3 years ago
Que relacion tiene Las palabras: fermentacion-vino y clonacion- dolly​
rjkz [21]

Answer:

Al final, la hembra adulta da a luz a un animal que tiene la misma composición genética que el animal que donó la célula somática. A esta cría se le conoce como clon. La clonación reproductiva podría requerir el uso de una madre sustituta para hacer posible el desarrollo del embrión clonado, tal como fue el caso del más famoso.

Explanation:

4 0
3 years ago
What visual practice provides more information about logical relations when creating an ERD
Marina86 [1]

Answer:

Logical Data Model

Explanation:

An Entity Relationship Diagram (ERD) is a model or a diagram designed to reveal the relationship between various entities such as people, places, objects, and so on within an institution. Entity relationship diagram is also known as Entity relationship model. This model is used to design relational database by various sectors such as education, engineering, business, etc.

<u>ERD is designed using conceptual data model, logical data model, and physical data model</u>.

The visual practice or model that gives more insight into the logical relations among the entity is the logical data model.

The logical data model is used to illustrate more detailed operational and relational data among the entities. It is more detailed than the conceptual data.

So, the correct answer is logical data model.

5 0
3 years ago
What is a feature of Print Preview? Fit to Document Fit to Margin Fit to Page Fit to Size
Rudiy27
Fit to page! Is a feature that
7 0
3 years ago
Read 2 more answers
Other questions:
  • You have just deployed SNMPv3 in your environment. Your manager asks you to make sure that your SNMP agents can only talk to the
    13·2 answers
  • What is the opportunity cost of computers when moving from point A to point B? -15 DVDs b. What is the opportunity cost of compu
    13·1 answer
  • A computer with a domain name is called a
    8·2 answers
  • Write a MIPS program to generate the following series of integers: 1, 2, 3. 6, 9, 18. 27, 54. 81. If you are curious where this
    13·1 answer
  • Which method do software testers use to isolate new code from the rest of the network during the test stage of the software deve
    15·1 answer
  • Explain how software is distinct from hardware.
    8·2 answers
  • Bcr is an out put device true or false​
    13·2 answers
  • 1 paint 2 anahaw leaf 3 shellac 4 varnish 5 metal sheets 6 paint 7 G.I. pipe 8 enamel paint 9 bamboo 10 fillers
    14·1 answer
  • In which languages the dynamic web pages are written?<br>​
    10·1 answer
  • Your task is to design a method int[] allMatches(int[] values, int size, int a, int b) that returns all values between a and b i
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!