Java algs11 package
Write a program to prompt the user for 2 floating point numbers, A & B. The program should print, on separate lines: • The sum of the two numbers A + B • The difference of the two numbers A - B • The quotient (first/second) A / B • The quantity: AB, Hint pow( )
package algs11; import java.util.Scanner; public class MathOperations { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter two floating-point numbers: "); double n1 = in.nextDouble(); double n2 = in.nextDouble(); System.out.println("Sum: " + (n1+n2)); System.out.println("Difference: " + (n1-n2)); System.out.println("Quotient: " + (n1/n2)); System.out.println(n1 + " power " + n2 + " is " + Math.pow(n1, n2)); } }
Get Answers For Free
Most questions answered within 1 hours.