import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Calculator program
Scanner scanner = new Scanner(System.in);
double num1;
double num2;
char operator;
double result = 0;
boolean validOperation = true;
System.out.print("Enter the first number: ");
num1 = scanner.nextDouble();
System.out.print("Enter an operator (+, -,/, ^): ");
operator = scanner.next().charAt(0);
System.out.print("Enter the second number: ");
num2 = scanner.nextDouble();
switch (operator){
case '+' -> result = num1 + num2;
case '-' -> result = num1 - num2;
case '*' -> result = num1 * num2;
case '/' -> {
if (num2 == 0) {
System.out.println("Cannot divide by zero!");
validOperation = false;
} else {
result = num1 / num2;
}
}
case '^' -> result = Math.pow(num1, num2);
default -> {
System.out.println("Invalid operator!");
validOperation = false;
}
}
if(validOperation) {
System.out.println(result);
}
scanner.close();
}
}
Forwarded from Azim Pulat
This media is not supported in your browser
VIEW IN TELEGRAM
I just made internet a better place with this PR https://github.com/hugomd/ascii-live/pull/2
curl ascii.live/rick
curl ascii.live/rick
Lol Javada Class nomi File nomi bilan birxil boΚ»lishi kerak ekan π€―
Btw Kotlin, C#, Swift ham shunaqa edi
Btw Kotlin, C#, Swift ham shunaqa edi
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
1
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
wie bitte π΅
Video message
Fundamental of IT
Programmingda doim hindlar boΚ»ganπ
Programmingda doim hindlar boΚ»gan
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM