Question

In: Computer Science

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.

For example: if the user enters numbers 11 and 7, your program output should look EXACTLY like this:

Please enter real number N1: 11
Please enter real number N2: 7
11.000000 * 7.000000 = 77.00
11.000000 / 7.000000 = 1.57
11.000000 raised to the power of 7.000000 = 19487171.00

As another example: if the user enters numbers 3.25 and 10.3, your program output should look EXACTLY like this:

Please enter real number N1: 3.25
Please enter real number N2: 10.3
3.250000 * 10.300000 = 33.48
3.250000 / 10.300000 = 0.32
3.250000 raised to the power of 10.300000 = 187239.99

Solutions

Expert Solution

import java.util.Scanner;

public class TestOperations {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       // reading numbers
       System.out.println("Please enter real number N1: ");
       double n1 = sc.nextDouble();
       System.out.println("Please enter real number N2: ");
       double n2 = sc.nextDouble();
       // printing product
       System.out.printf("%f * %f = %f\n", n1, n2, n1 * n2);
       // printing division
       System.out.printf("%f / %f = %f\n", n1, n2, n1 / n2);
       // printing power
       System.out.printf("%f raised to the power of %f = %f", n1, n2, Math.pow(n1, n2));
   }
}

Note : If you like my answer please rate and help me it is very Imp for me


Related Solutions

In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
In a file called LengthSum.java, write a program that: Asks the user to enter a string....
In a file called LengthSum.java, write a program that: Asks the user to enter a string. Asks the user to enter a second string. Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please enter a second...
In a file called Conversions.java, write a program that: Asks the user to enter a double...
In a file called Conversions.java, write a program that: Asks the user to enter a double number. Stores that number into a variable called z. Casts variable z into an integer, and stores the result into a variable called z1. Creates a variable z2, and sets it equal to the integer closest to z. Creates a variable z3, and sets it equal to the floor of z. Creates a variable z4, and sets it equal to the ceiling of z....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string. Prints out four different versions of that string: The original version of the string. The upper-case version of the string. The lower-case version of the string. A version where the character at position 0 capitalized, and all other characters in lower case. For example: if the user enters string "gaNDalF12 !! AB3w", your program output should look EXACTLY like this: Please enter a string:...
In a file called DivisibilityTests.java, write a program that: Asks the user to enter an integer....
In a file called DivisibilityTests.java, write a program that: Asks the user to enter an integer. It is OK for your program to crash when the user does not enter a valid integer. If the integer is less than 0, the program prints: "The number is negative." If the integer is divisible by 2 and by 3, the program prints: "The number is even and divisible by 3." If the integer is divisible by 2 but not by 3, the...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
IN JAVA Write a complete program that asks the user to enter two real numbers from...
IN JAVA Write a complete program that asks the user to enter two real numbers from the console. If both numbers are positive print the product, if both numbers are negative print the quotient, otherwise print INVALID INPUT. Use a nested if; output should be to a dialog and console; use printf to format the console output (for real numbers specify the width and number of digits after the decimal). The output must be labeled. Follow Java conventions, indent your...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
In a file called NumbersToMonths.java, write a program that: Asks the user to specify a month...
In a file called NumbersToMonths.java, write a program that: Asks the user to specify a month as an integer between 1 and 12. It is OK for your program to crash when the user does not enter a valid integer. Prints out the name of the corresponding month. Prints out "This number does not correspond to a month." if the integer is less than 1 or greater than 12. For example: if the user enters 1, your program output should...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings. First, the program prompts: Please enter a string. The program should read in the string, and prompts: Please enter another string. The program reads in two strings and it prints a menu to the user. The program asks for user to enter an option and performs one of the following: Here are the options on the menu: Option a: checks if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT