Das Ganze in Java : Code: Sprache: Java Effektive Zeilen: 47 Größe des Source in Byte: 1328 Größe der Binary in Byte: 2038 Art der Binary: Java Bytecode API: keine Benötigt: java.io.IOException, java.io.InputStreamReader Compiler: Blackdown JDK-1.4.1 Kompiliert als: javac Main.java Code: import java.io.InputStreamReader; import java.io.IOException; public class Main { public static String readLine() { InputStreamReader isr=new InputStreamReader(System.in); char c; String line=""; try { do { c=(char) isr.read(); if (c!='\n') line = line+c; } while (c!='\n'); } catch (IOException ex) { } return line; } public static void main(String[] args) { float z1,z2; String op=""; char c; System.out.println("Hallo Welt."); System.out.print("Erste Zahl eingeben: "); z1=Float.parseFloat(readLine()); System.out.print("Zweite Zahl eingeben: "); z2=Float.parseFloat(readLine()); System.out.println(op); do { System.out.print("Bitte Operation waehlen + - * / "); op=readLine(); } while ( !(op.equals("+") || op.equals("-") || op.equals("*") || op.equals("/")) ); switch (op.charAt(0)) { case '+': System.out.println(z1+" + "+z2+" = "+(z1+z2)); break; case '-': System.out.println(z1+" - "+z2+" = "+(z1-z2)); break; case '*': System.out.println(z1+" * "+z2+" = "+(z1*z2)); break; case '/': System.out.println(z1+" / "+z2+" = "+(z1/z2)); break; default: break; } System.out.println("Danke fuer die Benutzung. Zum Beenden Enter druecken."); readLine(); } } Testlauf: Code: fuero@bmfh classes $ java Main Hallo Welt. Erste Zahl eingeben: 23 Zweite Zahl eingeben: 56 Bitte Operation waehlen + - * / + 23.0 + 56.0 = 79.0 Danke fuer die Benutzung. Zum Beenden Enter druecken.
Sprache: Java Effektive Zeilen: 47 Größe des Source in Byte: 1328 Größe der Binary in Byte: 2038 Art der Binary: Java Bytecode API: keine Benötigt: java.io.IOException, java.io.InputStreamReader Compiler: Blackdown JDK-1.4.1 Kompiliert als: javac Main.java
import java.io.InputStreamReader; import java.io.IOException; public class Main { public static String readLine() { InputStreamReader isr=new InputStreamReader(System.in); char c; String line=""; try { do { c=(char) isr.read(); if (c!='\n') line = line+c; } while (c!='\n'); } catch (IOException ex) { } return line; } public static void main(String[] args) { float z1,z2; String op=""; char c; System.out.println("Hallo Welt."); System.out.print("Erste Zahl eingeben: "); z1=Float.parseFloat(readLine()); System.out.print("Zweite Zahl eingeben: "); z2=Float.parseFloat(readLine()); System.out.println(op); do { System.out.print("Bitte Operation waehlen + - * / "); op=readLine(); } while ( !(op.equals("+") || op.equals("-") || op.equals("*") || op.equals("/")) ); switch (op.charAt(0)) { case '+': System.out.println(z1+" + "+z2+" = "+(z1+z2)); break; case '-': System.out.println(z1+" - "+z2+" = "+(z1-z2)); break; case '*': System.out.println(z1+" * "+z2+" = "+(z1*z2)); break; case '/': System.out.println(z1+" / "+z2+" = "+(z1/z2)); break; default: break; } System.out.println("Danke fuer die Benutzung. Zum Beenden Enter druecken."); readLine(); } }
fuero@bmfh classes $ java Main Hallo Welt. Erste Zahl eingeben: 23 Zweite Zahl eingeben: 56 Bitte Operation waehlen + - * / + 23.0 + 56.0 = 79.0 Danke fuer die Benutzung. Zum Beenden Enter druecken.
--post tenebras lux, post fenestras tux
Foren-Regeln