Use the Scanner class to read them into double variables. Print out the result o
ID: 3747898 • Letter: U
Question
Use the Scanner class to read them into double variables. Print out the result of the four basic arithmetic operations (addition, subtraction, multiplication, and division) on the two numbers Use the Scanner class to read them into double variables. Print out the result of the four basic arithmetic operations (addition, subtraction, multiplication, and division) on the two numbers Use the Scanner class to read them into double variables. Print out the result of the four basic arithmetic operations (addition, subtraction, multiplication, and division) on the two numbersExplanation / Answer
import java.util.Scanner; public class ArithmeticOperations { public static void main(String[] args) { Scanner in = new Scanner(System.in); double n1, n2; System.out.print("Enter two numbers: "); n1 = in.nextDouble(); n2 = in.nextDouble(); // calculate and display results. System.out.println(n1 + " + " + n2 + " = " + (n1 + n2)); System.out.println(n1 + " - " + n2 + " = " + (n1 - n2)); System.out.println(n1 + " * " + n2 + " = " + (n1 * n2)); if(n2 == 0) System.out.println("Division by 0 is not possible."); else System.out.println(n1 + " / " + n2 + " = " + (n1 / n2)); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.