In: Computer Science
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!
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: