Advertisement
Guest User

Taschenrechner Simon Köck

a guest
Mar 29th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Programm {
  3.  
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7.  
  8.  
  9. Scanner rechenart = new Scanner(System.in);
  10. double zahl1, zahl2;
  11. int eingabe;
  12. String frage = "f";
  13.  
  14.  
  15. while(frage.equals("f")) {
  16.  
  17. System.out.println("Was wollen Sie tun?\n1.) Addieren \n2.) Subtrahieren \n3.) Dividieren"
  18. + "\n4.) Multiplizieren");
  19. eingabe = rechenart.nextInt();
  20.  
  21. System.out.println("Geben Sie die Erste Zahl ein!");
  22. zahl1 = rechenart.nextDouble();
  23. System.out.println("Geben Sie die zweite Zahl ein!");
  24. zahl2 = rechenart.nextDouble();
  25.  
  26.  
  27.  
  28. switch(eingabe) {
  29.  
  30. case 1:
  31. System.out.println(Adieren(zahl1,zahl2));
  32. break;
  33. case 2:
  34. System.out.println(Subtrahieren(zahl1,zahl2));
  35. break;
  36. case 3:
  37. System.out.println(Dividieren(zahl1,zahl2));
  38.  
  39. break;
  40. case 4:
  41. System.out.println(multiplizieren(zahl1,zahl2));
  42. break;
  43.  
  44. }
  45. }
  46. rechenart.close();
  47. }
  48. public static double Adieren(double zahl1, double zahl2) {
  49. return zahl1 + zahl2;
  50. }
  51. public static double Subtrahieren(double zahl1, double zahl2) {
  52. return zahl1 - zahl2;
  53. }
  54. public static double Dividieren(double zahl1, double zahl2) {
  55. return zahl1 / zahl2;
  56. }
  57. public static double multiplizieren(double zahl1, double zahl2) {
  58. return zahl1 * zahl2;
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement