Advertisement
Liverek

calculator

May 20th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Calculator {
  4. private int a;
  5. private int b;
  6. private int result;
  7. private String type;
  8. private String sentence;
  9. private boolean is = true;
  10.  
  11. public void setA(int a) {
  12. this.a = a;
  13. }
  14.  
  15. public void setB(int b) {
  16. this.b = b;
  17. }
  18.  
  19. public void add() {
  20. result = a + b;
  21. ResultManager add = new ResultManager(this.result);
  22. }
  23.  
  24. public void exponentiation() {
  25. type = "potegowania";
  26. result = (int) Math.pow(a, b);
  27. ResultManager power = new ResultManager(this.result, type);
  28. }
  29.  
  30. private boolean ifFirst(int x) {
  31.  
  32.  
  33. boolean is = true;
  34. for (int i = 2; i < x; i++) {
  35. if (x % i == 0) {
  36.  
  37. is = false;
  38. return is;
  39. }
  40.  
  41. }
  42. return is;
  43.  
  44. }
  45.  
  46.  
  47. public void getFirstNumbers() {
  48. boolean c;
  49. int j = 0;
  50. for (int i = a; i <= b; i++) {
  51. c = ifFirst(i);
  52. if (c == true) {
  53. j++;
  54. } else
  55. continue;
  56.  
  57. }
  58. String sentence = "Pomiedzy " + a + " i " + b + " jest " + j + " liczb pierwszych";
  59. new ResultManager(sentence);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement