Hello Jetto Family,
I will show you a calculator programme with a simple algorithm model in Java.
First of all, open any editor, IDE or notepad!
I will explain here on IntelliJ IDEA Community Edition! IntelliJ IDEA is a paid programme, but Community Edition is free!
You can find the download link by doing a short search on Google. 🙂
When you open the programme, you first need to import the library required to get data from the console!
You must define the above code above the Main class in the program.
Then we will start writing our codes in the main function!
First of all, we defined an object from the library we imported. We will use it when getting information from the console.
Then we get the first number and the second number from the console and assign them to variables.
All that remains is to do the operations and print them on the screen!
I am doing the simplest version here. Of course, it can be progressed by asking the user what to do. You can make better ones by developing!
As above, we use the calculations in the command to print to the screen.
Finally, you can specify a message according to your wishes. I have written the message ‘Calculation completed!’.
Thus, we have finished the program! Now it's time to put it to work!
As you can see, by entering two numbers, we have successfully performed the operation we wanted!
You can send your questions as a comment.
All codes:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the first number: ");
int firstNumber = s.nextInt();
System.out.println("Enter the second number: ");
int secondNumber = s.nextInt();
System.out.println("Sum: "+ (firstNumber + secondNumber));
System.out.println("Difference: "+ (firstNumber - secondNumber));
System.out.println("Multiplication : "+ (firstNumber * secondNumber));
System.out.println("Division: "+ (firstNumber - secondNumber));
System.out.println("Calculation completed!");
}
}
Daha Çok Göster