Question

In: Computer Science

Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....

Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers.

Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE:

public class Main {

public static void main(String[] args) {

// Write your code here

}

}

Sample input:

Input first number: 125
Input second number: 24

Sample Output:
125 + 24 = 149
125 - 24 = 101
125 x 24 = 3000
125 / 24 = 5

*Please include what system you used to write this. My course is not very descriptive, thank you!

Solutions

Expert Solution

JAVA code:

import java.util.*
;class sorting {
    public static void main(String[] args) {
        //scanner class
        Scanner sc = new Scanner(System.in);
        //taking inputs
        System.out.print("Input first number: ");
        int x = sc.nextInt(); //input x
        System.out.print("Input second number: ");
        int y = sc.nextInt();  //input y

        System.out.println();
        //printing results
        System.out.println(x + "+" + y + "=" + (x + y));  //addition
        System.out.println(x + "-" + y + "=" + (x - y));  //subtraction
        System.out.println(x + "x" + y + "=" + (x * y));  //multiplicaation
        System.out.println(x + "/" + y + "=" + (x / y));  //division


    }
}

OUTPUT:


Related Solutions

Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The program will add, subtract, multiply, or divide 2 numbers and provide the average of multiple numbers inputted from the user. You need to define a function named performCalculation which takes 1 parameter. The parameter will be the operation being performed (+,-,*,/). This function will perform the given prompt from the user for 2 numbers then perform the expected operation depending on the parameter that’s...
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
Ahrithmetic calculation about scientific notation. Mixed unit and multiplication, addition, subtraction, division too. this is my...
Ahrithmetic calculation about scientific notation. Mixed unit and multiplication, addition, subtraction, division too. this is my question above, please help me I need it to study.
Write a java program of a multiplication table of binary numbers using a 2D array of...
Write a java program of a multiplication table of binary numbers using a 2D array of integers.
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication,...
Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication, shift right, shift left, logical NAND, and logical NOR. Write a VHDL test bench to test the ALU with at least one test vector per operation.
1: Answer these questions: (a) Write a Java program to print whole numbers between 1 to...
1: Answer these questions: (a) Write a Java program to print whole numbers between 1 to 1000 which are divisible by 3, 5 and by both numbers. (b) Differentiate between instance and local variable in Java (c) In a tabular form, differentiate between instance and class variable
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
Write a C++ program to perform two-4 bit binary number operations including addition and subtraction. The...
Write a C++ program to perform two-4 bit binary number operations including addition and subtraction. The user will type in two-4 bit binary numbers with the selection of one of the operations. Then, the program will calculate the result of the calculation. Display two-4 bit binary numbers and the result from the calculation.
What is the primary reason that addition and subtraction are considered more complex than multiplication and...
What is the primary reason that addition and subtraction are considered more complex than multiplication and division with floating-point representations? What are subnormal numbers, and how do subnormal numbers help reduce the impact of underflow?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT