Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
public class Calculadora {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("1st number: "); double num1 = scanner.nextDouble();
System.out.print("2nd number: "); double num2 = scanner.nextDouble();
System.out.print("Choose: (+, -, *, /): "); char operacion = scanner.next().charAt(0);
double result = 0; boolean validOp = true;
switch (operacion) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': if (num2 != 0) result = num1 / num2; else { System.out.println("Error: División por cero."); validOp = false; } break;
default: System.out.println("Not valid."); validOp = false; break;
}
if (validOp) System.out.println("Result is: " + result);
}
}