Question

Write a program that asks the user for three integers (firstInt, secondInt, thirdInt). Perform the following...

Write a program that asks the user for three integers (firstInt, secondInt, thirdInt). Perform the following operations and output the results:

  • firstResult = Add firstInt and secondInt then divide the result by thirdInt
  • secondResult = Multiply secondInt by thirdInt and divide result by the sum of secondInt and firstInt
  • thirdResult = Multiply firstInt by thirdInt and find the remainder of dividing the result by secondInt

Your prompts to the user to enter the integers must be:

Enter firstInt:
Enter secondInt:
Enter thirdInt:

Your output must be of the format:

First Result = firstResult
Second Result = secondResult
Third Result = thirdResult

Please make sure to end each line of output with a newline.

Homework Answers

Answer #1

Screenshot of the code:

Sample Output:

Code to copy:

import java.util.Scanner;

public class Integer_operations

{

      //main function

      public static void main(String[] args)

      {

               //Create a new object of Scanner class and

               //store it in variable input.

              Scanner sc = new Scanner(System.in);

              

              //Declare the necessary variables

              int firstInt, secondInt, thirdInt;

              int firstResult, secondResult, thirdResult;

              //Prompt the user to enter the first integer.

              System.out.print("Enter firstInt: ");

              firstInt = sc.nextInt();

              //Prompt the user to enter the second integer.

              System.out.print("Enter secondInt: ");

              secondInt = sc.nextInt();

              //Prompt the user to enter the third integer.

              System.out.print("Enter thirdInt: ");

              thirdInt = sc.nextInt();

              //Add firstInt and secondInt and divide result

              // by thirdInt

              firstResult = (firstInt+secondInt)/(thirdInt);

             

              //Multiply secondInt by thirdInt and divide

              // result by sum of second and firstInt.

              secondResult = (secondInt*thirdInt)/(secondInt+firstInt);

             

              //Multiply firstInt by thirdInt and find the

              //remainder by dividing result by secondInt.

              thirdResult = (firstInt*thirdInt)%secondInt;

             

              //Display the desired results stored in variables

              // firstResult,secondResult and thirdResult.

              System.out.println("First Result = "+firstResult);

              System.out.println("Second Result = "+secondResult);

              System.out.println("Third Result = "+thirdResult);

          }

}

Know the answer?
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
Similar Questions
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
Write a Python program that prompts a user for two integers and stores the two integers...
Write a Python program that prompts a user for two integers and stores the two integers the user types into the shell. Print the product, float division, integer division, remainder, sum, and difference of the two integers to the console. The entire equation must be printed (see below for formatting). Only display 2 digits after the decimal place for results that are floats. Include a module docstring that summarizes the program.. Sample Run 1: Enter an integer: 5 Enter another...
1. Write a complete program in C++ that does the following: [2] asks a user to...
1. Write a complete program in C++ that does the following: [2] asks a user to enter two integer numbers (display a warning message that the second number should be different from zero) [3] reads the two numbers from the keyboard; [4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one. [3] displays the result of floating-point division. Make sure to follow programming style guidelines.
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b,...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b, c, and then computes the results of the following logical operations, in sequence: !a || !b++ && c (a-1 || b/2) && (c*=2) (a-- || --b) && (c+=2) a || !(b && --c)
In a file called ThreeOperations.java, write a program that: Asks the user to enter two real...
In a file called ThreeOperations.java, write a program that: Asks the user to enter two real numbers (doubles, not integers) called N1 and N2. It is OK if your program crashes when the user does not enter valid double numbers. Computes and displays the following operations between the two: multiplication, division, exponentiation. For the results of these two operations, only two decimal digits should be displayed.
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
Write a program that asks the user to enter three different integers; if the entered three...
Write a program that asks the user to enter three different integers; if the entered three integers contain two or more that are the same, print message "wrong input"; otherwise the program prints the largest number in the three. Implement your code using decision structures (namely, if and/or if-else). In the execution of your code, try the following test cases. Test case 1: input (3, 4, 5) Test case 2: input (3, 3, 5) Test case 3: input (3, 5,...
Write a C program that asks the user to enter two integers x and n. Then...
Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. using printf scanf
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user to input two integers. - If both of them are greater than zero, then output their sum. - If only one integer is greater than zero, then output their difference. - Otherwise, output a message "your two number <0".
Write a program that asks the user to enter a U.S. dollar amount and then shows...
Write a program that asks the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $100, $20, $10, and $5 bills. Following are a few test cases for your program: Enter the amount for withdrawal: 125 Please collect your bills as follows: $100: 1 $20: 1 $5: 1 Enter the amount for withdrawal: 94 The amount cannot be withdrawn. Note: Be sure to use integer values throughout, not floating...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT