1 // IntArithmetik.java
2 import java.util.Scanner;
3
4 /** 5 * IntArithmetik testet die arithmetischen Operatoren mit ganzen Zahlen. 6 * Beispielprogramm zur Programmiertechnik 1, Teil 3. 7 * @author H.Drachenfels 8 * @version 17.3.2023 9 */
10 public final class IntArithmetik {
11 private IntArithmetik() { }
12
13 private static final Scanner EINGABE = new Scanner(System.in);
14
15 /** 16 * main ist der Startpunkt des Programms. 17 * @param args wird nicht verwendet. 18 */
19 public static void main(String[] args) {
20 System.out.print("Zwei ganze Zahlen eingeben: ");
21
22 int a = EINGABE.nextInt();
23 int b = EINGABE.nextInt();
24
25 System.out.printf("-(%d): %d%n", a, -a);
26 System.out.printf("~%d: %d%n", a, ~a);
27 System.out.printf("~%d: %d%n", b, ~b);
28 System.out.printf("%d + %d: %d%n", a, b, a + b);
29 System.out.printf("%d - %d: %d%n", a, b, a - b);
30 System.out.printf("%d * %d: %d%n", a, b, a * b);
31 System.out.printf("%d / %d: %d%n", a, b, a / b);
32 System.out.printf("%d %% %d: %d%n", a, b, a % b);
33 System.out.printf("%d / %d: %d%n", b, a, b / a);
34 System.out.printf("%d %% %d: %d%n", b, a, b % a);
35 System.out.printf("%d & %d: %d%n", a, b, a & b);
36 System.out.printf("%d | %d: %d%n", a, b, a | b);
37 System.out.printf("%d ^ %d: %d%n", a, b, a ^ b);
38 System.out.printf("%d << %d: %d%n", a, b, a << b);
39 System.out.printf("%d >> %d: %d%n", a, b, a >> b);
40 System.out.printf("%d >>> %d: %d%n", a, b, a >>> b);
41 System.out.printf("-(%d) >> %d: %d%n", a, b, -a >> b);
42 System.out.printf("-(%d) >>> %d: %d%n", a, b, -a >>> b);
43 }
44 }
45