![]() |
Willkommen, Gast ( Anmelden | Registrierung )
![]() |
![]()
Beitrag
#1
|
|
![]() Feuerteufel ![]() ![]() ![]() ![]() ![]() ![]() Gruppe: Mitglieder Beiträge: 2.228 Mitglied seit: 22.08.2004 Mitglieds-Nr.: 1.348 ![]() |
Ich habe eine Frage, wie kann ich eine zwei If-Überprüfung in eine If-Andwendung.
Soweit bin schon, aber mir fehlt der Operator zur Verbindung der zwei Abfragen: if(ausdruck1 ausdruck2) -------------------- |
|
|
![]() |
![]() ![]()
Beitrag
#2
|
|
Womanizer ![]() Gruppe: Freunde Beiträge: 3.798 Mitglied seit: 05.05.2004 Mitglieds-Nr.: 765 ![]() |
Häng dich da mal ordentlich rein, Florian. Das ist nicht schwer!
QUELLTEXT import java.util.Scanner;
public class TaschenRechner { public static void main(String[] args) { double x = 0; double y = 0; int a = 0; System.out.println("Für Operatoren Plus = 1, Minus = 2, Mal = 3, geteilt = 4, Wurzel ziehen = 5, Potenzieren = 6"); System.out.println("Bitte Operator eingeben: "); Scanner sc = new Scanner(System.in); a = sc.nextInt(); switch (a) { case 5: System.out.println("Bitte Wurzelexponent eingeben: "); x = sc.nextDouble(); System.out.println("Bitte Radikant eingeben: "); y = sc.nextDouble(); break; case 6: System.out.println("Bitte Basis eingeben: "); x = sc.nextDouble(); System.out.println("Bitte Exponent eingeben: "); y = sc.nextDouble(); break; default: System.out.println("Bitte ersten Operand eingeben: "); x = sc.nextDouble(); System.out.println("Bitte zweiten Operand eingeben: "); y = sc.nextDouble(); break; } switch(a) { case 1: System.out.print( "Ergebnis: " + x + " + " + y + " = "); System.out.println( x + y ); break; case 2: System.out.print( "Ergebnis: " + x + " - " + y + " = "); System.out.println( x - y ); break; case 3: System.out.print( "Ergebnis: " + x + " * " + y + " = "); System.out.println( x * y ); break; case 4: if (y == 0) { System.out.println("Durch 0 kann nicht geteilt werden."); } else { System.out.print( "Ergebnis: " + x + " / " + y + " = "); System.out.println( x / y ); } break; case 5: if (x == 0) { System.out.println("Die 0-te Wurzel ist nicht definiert"); } else { System.out.print( "Ergebnis: " + x + "-te Wurzel aus " + y + " = "); System.out.println(Math.pow(y, 1/x)); } break; case 6: System.out.print( "Ergebnis: " + x + " hoch " + y + " = "); System.out.println(Math.pow(x, y)); break; default: System.out.println("Keine gültige Auswahl"); break; } } } -------------------- |
|
|
![]() ![]() |
Vereinfachte Darstellung | Aktuelles Datum: 06.07.2025, 15:31 |