You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package programmiermethoden_und_Werkzeuge;
  2. import java.util.Scanner;
  3. public class Taschenrechner {
  4. int addition(int a, int b) {
  5. return a + b;
  6. }
  7. int multiplikation(int a, int b) {
  8. return a * b;
  9. }
  10. int division(int a, int b) {
  11. return a / b;
  12. }
  13. int potenzieren(int a, int b) {
  14. int temp = 1;
  15. if(b == 0) {
  16. return 1;
  17. }
  18. for(int i = 0; i < b; i++) {
  19. temp = temp * a;
  20. }
  21. return temp;
  22. }
  23. boolean kleinerAls(int a, int b) {
  24. return a < b;
  25. }
  26. boolean groeßerAls(int a, int b) {
  27. return a > b;
  28. }
  29. boolean gleich(int a, int b) {
  30. return a == b;
  31. }
  32. int randomNummer(int a, int b) {
  33. //Zufällige Nummer von a bis b
  34. int temp = 0;
  35. temp = (int) (Math.random() * (b + 1) ) + a;
  36. return temp;
  37. }
  38. double pie() {
  39. return Math.PI;
  40. }
  41. void startTaschenrechner() {
  42. //Funktion zum Starten des Taschenrechnerprogramms
  43. System.out.println("1.Addition, 2.Multiplikation, 3.Division, 4.Potenzieren, 5.kleinerAls, 6.groeßerAls, 7.Gleichgroß, 8.Zufällige Zahl, 9.PI");
  44. Scanner scan = new Scanner(System.in);
  45. int s = scan.nextInt();
  46. scan.close();
  47. switch (s) {
  48. case 1: {
  49. addition(s, s);
  50. break;
  51. }
  52. case 2: {
  53. division(s, s);
  54. break;
  55. }
  56. default:
  57. throw new IllegalArgumentException("Unexpected value: " + s);
  58. }
  59. }
  60. }