Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. package at.kilian.hue;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Beispiele {
  6. public static void main(String[] args) {
  7.  
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println(
  10. "a)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  11. System.out.println("Geben sie a ein:");
  12. int a = sc.nextInt();
  13.  
  14. System.out.println("Geben sie b ein:");
  15. int b = sc.nextInt();
  16.  
  17. int su = a + b;
  18. System.out.println("Summe = " + su);
  19.  
  20. int dif = a - b;
  21. System.out.println("Differenz = " + dif);
  22.  
  23. int pro = a * b;
  24. System.out.println("Produkt = " + pro);
  25.  
  26. double quo = (double) a / b;
  27. System.out.println("Quotient = " + quo);
  28. System.out.println();
  29. System.out.println(
  30. //Aufgabe 2
  31. "b)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  32.  
  33. System.out.print("Geben sie d1 ein:");
  34. double d1 = sc.nextDouble();
  35.  
  36. System.out.print("Geben sie d2 ein:");
  37. double d2 = sc.nextDouble();
  38.  
  39. double sud = d1 + d2;
  40. System.out.println("Summe = " + sud);
  41.  
  42. double difd = d1 - d2;
  43. System.out.println("Differenz = " + difd);
  44.  
  45. double prod = d1 * d2;
  46. System.out.println("Produkt = " + prod);
  47.  
  48. double quod = d1 / d2;
  49. System.out.println("Quotient = " + quod);
  50. System.out.println();
  51. System.out.println(
  52. //Aufgabe 3
  53. "c)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  54.  
  55. for (int i = 1; i <= 10; i++) {
  56. System.out.printf("Das ist die %dte Zeile%n", i);
  57. }
  58.  
  59. System.out.println();
  60. System.out.println(
  61. //Aufgabe 4
  62. "d)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  63.  
  64. for (int g = 1; g <= 15; g++) {
  65. double rd = Math.random();
  66. if (rd <= 0.5) {
  67. System.out.printf("%.2f Die Zahl ist kleiner%n", rd);
  68. } else {
  69. System.out.printf("%.2f Die Zahl ist größer%n", rd);
  70. }
  71.  
  72. }
  73.  
  74. System.out.println();
  75. System.out.println(
  76. //Aufgabe 5
  77. "e)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  78.  
  79. 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"
  80. + "3 6 9 12 15 18 21 24 27 30\r\n" + "4 8 12 16 20 24 28 32 36 40\r\n"
  81. + "5 10 15 20 25 30 35 40 45 50\r\n" + "6 12 18 24 30 36 42 48 54 60\r\n"
  82. + "7 14 21 28 35 42 49 56 63 70\r\n" + "8 16 24 32 40 48 56 64 72 80\r\n"
  83. + "9 18 27 36 45 54 63 72 81 90\r\n" + "10 20 30 40 50 60 70 80 90 100");
  84.  
  85. System.out.println();
  86. System.out.println(
  87. //Aufgabe 6
  88. "f)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  89.  
  90. System.out.println("Geben Sie eine Note ein:");
  91. double note = sc.nextDouble();
  92.  
  93. double notensumme = 0;
  94.  
  95. double note1 = 0, note2 = 0, note3 = 0, note4 = 0, note5 = 0;
  96.  
  97. while (note != 0) {
  98. notensumme = notensumme + note;
  99. if (note == 1) {
  100. note1++;
  101. } else if (note == 2) {
  102. note2++;
  103. } else if (note == 3) {
  104. note3++;
  105. } else if (note == 4) {
  106. note4++;
  107. } else if (note == 5) {
  108. note5++;
  109. }
  110. System.out.println("Geben sie eine weitere Note ein oder 0 zum beenden:");
  111. note = sc.nextDouble();
  112.  
  113. }
  114. double notenanzahl = note1 + note2 + note3 + note4 + note5;
  115.  
  116. double schnitt = notensumme / notenanzahl;
  117.  
  118. System.out.printf("Sie haben %.0f Sehrgut%n" + "Sie haben %.0f Gut%n" + "Sie haben %.0f Befriedigend%n"
  119. + "Sie haben %.0f Genügend%n" + "Sie haben %.0f Nicht Genügend%n"
  120. + "Sie haben einen Notenschnitt von %.4f", note1, note2, note3, note4, note5, schnitt);
  121.  
  122. System.out.println();
  123. System.out.println(
  124. //Aufgabe 7
  125. "g)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  126.  
  127. System.out.println("Bitte geben sie eine Zahl ein :");
  128. int zahl = sc.nextInt();
  129.  
  130. while (zahl != 0) {
  131. if (zahl % 2 == 0) {
  132. System.out.println("Die Zahl ist gerade.");
  133. } else {
  134. System.out.println("Die Zahl ist ungerade.");
  135. }
  136. System.out.println("Bitte geben sie noch eine Zahl ein oder 0 um zu beenden:");
  137. zahl = sc.nextInt();
  138. System.out.println();
  139. System.out.println(
  140. //Aufgabe 7
  141. "h)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  142. System.out.println("Bitte geben sie eine Zahl ein :");
  143. int input_h = sc.nextInt();
  144. while (input_h != 0) {
  145. if (input_h == 0) {
  146. System.err.println("Ende");
  147. }
  148.  
  149. if (input_h == 1) {
  150. int erg = 1 * 1;
  151. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  152. } else if (input_h == 2) {
  153. int erg = 1 * 2;
  154. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  155. } else if (input_h == 3) {
  156. int erg = 1 * 2 * 3;
  157. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  158. } else if (input_h == 4) {
  159. int erg = 1 * 2 * 3 * 4;
  160. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  161. } else if (input_h == 5) {
  162. int erg = 1 * 2 * 3 * 4 * 5;
  163. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  164. } else if (input_h == 6) {
  165. int erg = 1 * 2 * 3 * 4 * 5 * 6;
  166. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  167. } else if (input_h == 7) {
  168. int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7;
  169. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  170. } else if (input_h == 8) {
  171. int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8;
  172. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  173. } else if (input_h == 9) {
  174. int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9;
  175. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  176. } else {
  177. int erg = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10;
  178. System.out.printf("Fakultät von %d: %d%n", input_h, erg);
  179. }
  180. System.out.println("Bitte geben sie noch eine Zahl ein oder 0 um zu beenden:");
  181. input_h = sc.nextInt();
  182. System.out.println();
  183. System.out.println(
  184. // Aufgabe 8
  185. "i)//////////////////////////////////////////////////////////////////////////////////////////////////////////////");
  186.  
  187. }
  188. }
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement