/* Aufgabe1a.java */ /* * @author Benjamin Kormann */ public class Aufgabe1a { public static void main(String args[]) { double basis = Double.valueOf(args[0]).doubleValue(); int exp = Integer.valueOf(args[1]).intValue(); double res = 1; for(int i = 0; i < Math.abs(exp); i++) res *= basis; if (exp < 0) res = 1 / res; System.out.println(res); } } /* Aufgabe1b.java */ /* * @author Benjamin Kormann */ public class Aufgabe1b { public static void main(String args[]) { double x[] = { 1.0, 2.0, 3.0 }; System.out.print("Vektor x:\n( "); for(int i = 0; i < x.length; i++) { System.out.print(x[i]); if (i != x.length-1) System.out.print(", "); } System.out.println(" )"); } } /* Aufgabe1c.java */ /* * @author Benjamin Kormann */ public class Aufgabe1c { public static void main(String args[]) { double m[][] = { { -1.0, -2.0, -3.0, 5.0 }, { 0.0, 1.0, 0.0, 5.0 }, { 1.0, 2.0, 3.0, 5.0 } }; System.out.println("Matrix M:"); for(int i = 0; i < m.length; i++) { System.out.print("( "); for(int j = 0; j < m[i].length; j++) { System.out.print(m[i][j]); if (j != m[i].length-1) System.out.print(", "); } System.out.println(" )"); } } } /* Aufgabe2.java */ /* * @author Benjamin Kormann */ public class Aufgabe2 { public static void main(String args[]) { for(int i = -2; i < 3; i++) { try { System.out.println(i + ": " + i/i); } catch(ArithmeticException e) { System.out.println("0: Division by zero"); } } } } /* Aufgabe3.java */ /* * @author */ public class Aufgabe3 { public static void main(String args[]) { try { // Konvertieren double x = Double.valueOf(args[0]).doubleValue(); double y = Double.valueOf(args[1]).doubleValue(); // Ausgabe der ueber die Befehlszeile eingegebenen Zahlen System.out.println("x = " + x); System.out.println("y = " + y); // Binaere Arithmetik double z; z = x + y; System.out.println("z z = x - y; System.out.println("z z = x * y; System.out.println("z z = x / y; System.out.println("z mit den Operatoren + - * / = x + y = " + z); = x - y = " + z); = x * y = " + z); = x / y = " + z); // Unaere Arithmetik mit Inkrement- / Dekrementoperator Programmieren in Java x++; System.out.println("Nach x++: x = " + x); y--; System.out.println("Nach y--: y = " + y); z = x++; System.out.println("Nach z = x++: z = " + z + ", x = " + x); z = ++x; System.out.println("Nach z = ++x: z = " + z + ", x = " + x); System.out.println("x = " + x); System.out.println("y = " + y); z = ++x + y--; System.out.println("Nach z = ++x + y--: z = " + z + ", x = " + x + " y = " + y); System.out.println("x = " + x); System.out.println("y = " + y); z = x + y * ++y; System.out.println("Nach z = x + y * ++y: z = " + z + ", x = " + x + " y = " + y); z = 1.0 / 0.0; System.out.println("z = 1.0 / 0.0 = " + z); z = -1.0 / 0.0; System.out.println("z = -1.0 / 0.0 = " + z); z = 0.0 / 0.0; System.out.println("z = 0.0 / 0.0 = " + z); z = -0.0 / 0.0; System.out.println("z = -0.0 / 0.0 = " + z); z = 1.0 / 0.0 + 2.0; System.out.println("z = 1.0 / 0.0 + 2.0 = " + z); z = -1.0 / 0.0 + 2.0; System.out.println("z = -1.0 / 0.0 + 2.0 = " + z); z = 0.0 / 0.0 + 2.0; System.out.println("z = 0.0 / 0.0 + 2.0 = " + z); z = -0.0 / 0.0 + 2.0; System.out.println("z = -0.0 / 0.0 + 2.0 = " + z); } catch(Exception e) { System.out.println("Fehler bei der Eingabe: java a b"); System.out.println(e.getMessage()); } } } /* IntDemo.java */ /* * @author Benjamin Kormann */ public class IntDemo { public static void main(String args[]) { int i = 0; while(++i > 0) {} System.out.println("Ueberrascht???"); } }