2024-11-06 02:49:59 +05:30
|
|
|
// Importing basic stuff
|
|
|
|
import java.io.*; // Used for I/O operations
|
|
|
|
import java.util.*; // Contains basic utilities
|
2024-10-14 12:11:16 +05:30
|
|
|
|
|
|
|
class A3 {
|
2024-11-06 02:49:59 +05:30
|
|
|
// Class name has to be same as file name for Java
|
|
|
|
|
|
|
|
static {
|
|
|
|
// Used for loading the .so (on Linux) or .dll (on Windows) file when running
|
|
|
|
// This is the main so called "dynamic library"
|
|
|
|
System.loadLibrary("A3");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function declaration
|
|
|
|
// private indicates the function is private, duh!
|
|
|
|
// Use of native indicates the function body will be written in a language other than Java, such as C/C++
|
|
|
|
private native int add(int a, int b); // For addition
|
|
|
|
private native int sub(int a, int b); // For subtraction
|
|
|
|
private native int mul(int a, int b); // For multiplication
|
|
|
|
private native int div(int a, int b); // For division
|
|
|
|
|
|
|
|
public static void main(String[] args) { // the main function
|
|
|
|
Scanner sc = new Scanner(System.in); // For taking input
|
2024-10-14 12:11:16 +05:30
|
|
|
|
2024-11-06 02:49:59 +05:30
|
|
|
int a, b;// Declaring variables for calculation
|
|
|
|
int choice = 0; // Declaring variable for switch-case
|
|
|
|
|
|
|
|
// Take input for a and b values
|
|
|
|
System.out.print("\nValue of a:\t");
|
|
|
|
a = sc.nextInt();
|
|
|
|
System.out.print("\nValue of b:\t");
|
|
|
|
b = sc.nextInt();
|
|
|
|
|
|
|
|
// Main menu
|
|
|
|
while (true) {
|
|
|
|
System.out.println("----- MAIN MENU -----");
|
|
|
|
System.out.println("1 -> Addition");
|
|
|
|
System.out.println("2 -> Subtraction");
|
|
|
|
System.out.println("3 -> Multiplication");
|
|
|
|
System.out.println("4 -> Division");
|
|
|
|
System.out.println("5 -> Exit");
|
|
|
|
System.out.println("Choose an option:\t");
|
|
|
|
choice = sc.nextInt();
|
|
|
|
|
|
|
|
switch (choice) {
|
|
|
|
case 1:
|
|
|
|
new A3().add(a, b);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
new A3().sub(a, b);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
new A3().mul(a, b);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
new A3().div(a, b);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
System.out.println("## END OF CODE");
|
|
|
|
System.exit(0);
|
|
|
|
default:
|
|
|
|
System.out.println("Please choose a valid option.");
|
|
|
|
break;
|
|
|
|
}
|
2024-10-14 12:11:16 +05:30
|
|
|
}
|
2024-11-06 02:49:59 +05:30
|
|
|
}
|
2024-10-14 12:11:16 +05:30
|
|
|
}
|