Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package at.kilian.hue;
- import java.util.Scanner;
- public class Beispiele {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println(
- "a)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- System.out.println("Geben sie a ein:");
- int a = sc.nextInt();
- System.out.println("Geben sie b ein:");
- int b = sc.nextInt();
- int su = a + b;
- System.out.println("Summe = " + su);
- int dif = a - b;
- System.out.println("Differenz = " + dif);
- int pro = a * b;
- System.out.println("Produkt = " + pro);
- double quo = (double) a / b;
- System.out.println("Quotient = " + quo);
- System.out.println();
- System.out.println(
- //Aufgabe 2
- "b)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- System.out.print("Geben sie d1 ein:");
- double d1 = sc.nextDouble();
- System.out.print("Geben sie d2 ein:");
- double d2 = sc.nextDouble();
- double sud = d1 + d2;
- System.out.println("Summe = " + sud);
- double difd = d1 - d2;
- System.out.println("Differenz = " + difd);
- double prod = d1 * d2;
- System.out.println("Produkt = " + prod);
- double quod = d1 / d2;
- System.out.println("Quotient = " + quod);
- System.out.println();
- System.out.println(
- //Aufgabe 3
- "c)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- for (int i = 1; i <= 10; i++) {
- System.out.printf("Das ist die %dte Zeile%n", i);
- }
- System.out.println();
- System.out.println(
- //Aufgabe 4
- "d)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- for (int g = 1; g <= 15; g++) {
- double rd = Math.random();
- if (rd <= 0.5) {
- System.out.printf("%.2f Die Zahl ist kleiner%n", rd);
- } else {
- System.out.printf("%.2f Die Zahl ist größer%n", rd);
- }
- }
- System.out.println();
- System.out.println(
- //Aufgabe 5
- "e)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- System.out.printf("1 2 3 4 5 6 7 8 9 10\r\n" + "2 4 6 8 10 12 14 16 18 20\r\n"
- + "3 6 9 12 15 18 21 24 27 30\r\n" + "4 8 12 16 20 24 28 32 36 40\r\n"
- + "5 10 15 20 25 30 35 40 45 50\r\n" + "6 12 18 24 30 36 42 48 54 60\r\n"
- + "7 14 21 28 35 42 49 56 63 70\r\n" + "8 16 24 32 40 48 56 64 72 80\r\n"
- + "9 18 27 36 45 54 63 72 81 90\r\n" + "10 20 30 40 50 60 70 80 90 100");
- System.out.println();
- System.out.println(
- //Aufgabe 6
- "f)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- System.out.println("Geben Sie eine Note ein:");
- double note = sc.nextDouble();
- double notensumme = 0;
- double note1 = 0, note2 = 0, note3 = 0, note4 = 0, note5 = 0;
- while (note != 0) {
- notensumme = notensumme + note;
- if (note == 1) {
- note1++;
- } else if (note == 2) {
- note2++;
- } else if (note == 3) {
- note3++;
- } else if (note == 4) {
- note4++;
- } else if (note == 5) {
- note5++;
- }
- System.out.println("Geben sie eine weitere Note ein oder 0 zum beenden:");
- note = sc.nextDouble();
- }
- double notenanzahl = note1 + note2 + note3 + note4 + note5;
- double schnitt = notensumme / notenanzahl;
- System.out.printf("Sie haben %.0f Sehrgut%n" + "Sie haben %.0f Gut%n" + "Sie haben %.0f Befriedigend%n"
- + "Sie haben %.0f Genügend%n" + "Sie haben %.0f Nicht Genügend%n"
- + "Sie haben einen Notenschnitt von %.4f", note1, note2, note3, note4, note5, schnitt);
- System.out.println();
- System.out.println(
- //Aufgabe 7
- "g)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- System.out.println("Bitte geben sie eine Zahl ein :");
- int zahl = sc.nextInt();
- while (zahl != 0) {
- if (zahl % 2 == 0) {
- System.out.println("Die Zahl ist gerade.");
- } else {
- System.out.println("Die Zahl ist ungerade.");
- }
- System.out.println("Bitte geben sie noch eine Zahl ein oder 0 um zu beenden:");
- zahl = sc.nextInt();
- System.out.println();
- System.out.println(
- //Aufgabe 7
- "h)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- System.out.println("Bitte geben sie eine Zahl ein :");
- int input_h = sc.nextInt();
- while (input_h != 0) {
- if (input_h == 0) {
- System.err.println("Ende");
- }
- if (input_h == 1) {
- int erg = 1 * 1;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 2) {
- int erg = 1 * 2;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 3) {
- int erg = 1 * 2 * 3;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 4) {
- int erg = 1 * 2 * 3 * 4;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 5) {
- int erg = 1 * 2 * 3 * 4 * 5;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 6) {
- int erg = 1 * 2 * 3 * 4 * 5 * 6;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 7) {
- int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 8) {
- int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else if (input_h == 9) {
- int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- } else {
- int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10;
- System.out.printf("Fakultät von %d: %d%n", input_h, erg);
- }
- System.out.println("Bitte geben sie noch eine Zahl ein oder 0 um zu beenden:");
- input_h = sc.nextInt();
- System.out.println();
- System.out.println(
- // Aufgabe 8
- "i)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement