Written in Java
import java.util.*;
public class Project01{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1,num2;
System.out.print("Enter first number: ");
num1 = input.nextInt();
System.out.print("Enter second number: ");
num2 = input.nextInt();
System.out.println(num1+" + "+num2+" = "+(num1 + num2));
System.out.println(num1+" - "+num2+" = "+(num1 - num2));
System.out.println(num1+" * "+num2+" = "+(num1 * num2));
System.out.println(num1+" / "+num2+" = "+(num1 / num2));
System.out.print("The average of your two numbers is: "+(num1 + num2)/2);
}
}
Explanation:
import java.util.*;
public class Project01
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
This line declares myfirstnum and mysecnum as integer
int myfirstnum,mysecnum;
This line prompts user for first number
System.out.print("Enter first number: ");
This line gets user input
myfirstnum= input.nextInt();
This line prompts user for second number
System.out.print("Enter second number: ");
This line gets user input
mysecnum = input.nextInt();
This line calculates and prints addition operation
System.out.println(myfirstnum+" + "+mysecnum+" = "+(myfirstnum + mysecnum));
This line calculates and prints subtraction operation
System.out.println(myfirstnum+" - "+mysecnum+" = "+(myfirstnum - mysecnum));
This line calculates and prints multiplication operation
System.out.println(myfirstnum+" * "+mysecnum+" = "+(myfirstnum * mysecnum));
This line calculates and prints division operation
System.out.println(myfirstnum+" / "+mysecnum+" = "+(myfirstnum / mysecnum));
This line calculates and prints the average of the two numbers
System.out.print("The average of your two numbers is: "+(myfirstnum + mysecnum)/2);
}
}