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.
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
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,
Gui calculator in Java with additon, subtraction, multiplication, division, sine, cosine, tangent, square, cube, raise to...
Gui calculator in Java with additon, subtraction, multiplication, division, sine, cosine, tangent, square, cube, raise to x to the power of y functionality. It should also have memory button, memory recall button and clear.
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.
Java program - you are not allowed to use arithmetic operations such as division (/), multiplication,...
Java program - you are not allowed to use arithmetic operations such as division (/), multiplication, or modulo (%) to extract the bits. In this exercise use only logic bit-wise operations. Write a program that prompts the user to enter a positive integer n (0 up to 232 -1). You must write a function that takes as input n and returns a string s representing the number n in binary. For this assignment, you CANNOT use the arithmetic division by...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT