In this program, we first define a class called ArithmeticalOperations. Within this class, we have a method called main which is the entry point of the program. The main method takes an array of strings as its argument, but we don't use it in this program.
Inside the main method, we declare two integer variables a and b and initialize them with values 10 and 5, respectively. We then perform several arithmetic operations on these variables and store the results in separate integer variables called sum, difference, product, quotient, and remainder.
public class ArithmeticalOperations { public static void main(String[] args) { int a = 10; int b = 5; int sum = a + b; int difference = a - b; int product = a * b; int quotient = a / b; int remainder = a % b; System.out.println("Sum: " + sum); System.out.println("Difference: " + difference); System.out.println("Product: " + product); System.out.println("Quotient: " + quotient); System.out.println("Remainder: " + remainder); } }
Finally, we print out the values of these variables using the System.out.println method. When we run this program, the output will be:
Sum: 15 Difference: 5 Product: 50 Quotient: 2 Remainder: 0
Comments
Post a Comment