Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public class Geek {
  2.  
  3. private String Name;
  4. private int NumberOfQuestions;
  5.  
  6. public Geek(String name) {
  7. this.Name = name;
  8. this.NumberOfQuestions = 0;
  9. }
  10.  
  11. public String getName() {
  12. return Name;
  13. }
  14.  
  15. public int getNumberOfQuestions() {
  16. return NumberOfQuestions;
  17. }
  18.  
  19. public boolean isEven(int num) {
  20. NumberOfQuestions++;
  21. if ((num % 2) == 0) {
  22. return true;
  23. } else {
  24. return false;
  25. }
  26. }
  27.  
  28. public String multiConcat(String text, int count) {
  29. NumberOfQuestions++;
  30. if (count < 2) {
  31. return text;
  32. }
  33. String Textout = "";
  34. for (int i = 0; i < count; i++) {
  35. Textout = Textout.concat(text);
  36. }
  37. return Textout;
  38. }
  39.  
  40. public int sumRange(int num1, int num2) {
  41. NumberOfQuestions++;
  42. if (num1 >= (num2 - 1)) {
  43. return 0;
  44. }
  45. int SumOfNumbers = 0;
  46. for (int i = ((num2 - 1) - num1); i > 0; i--) {
  47. SumOfNumbers = +num1 + i;
  48. }
  49. return SumOfNumbers;
  50. }
  51.  
  52. public boolean sorted(int num1, int num2, int num3) {
  53. NumberOfQuestions++;
  54. if (num2 < num1) {
  55. return false;
  56. }
  57. if (num3 < num2) {
  58. return false;
  59. }
  60. return true;
  61. }
  62.  
  63. public int countA(String text) {
  64. NumberOfQuestions++;
  65. int NumberOfA = 0;
  66. String LowerText = text.toLowerCase();
  67. for (int i = 0; i < text.length(); i++) {
  68. if ((LowerText.charAt(i)) == 'a') {
  69. NumberOfA++;
  70. }
  71. }
  72. return NumberOfA;
  73. }
  74.  
  75. public int countDigits(int num) {
  76. NumberOfQuestions++;
  77. int length = 0;
  78. String Numbers = "";
  79. Numbers = Integer.toString(num);
  80. length = Numbers.length();
  81. return length;
  82. }
  83.  
  84. public boolean isPrime(int num) {
  85. NumberOfQuestions++;
  86.  
  87. if(num<=1) {
  88. return false;
  89. }
  90.  
  91. for (int x = 2; x < num; x++) { // while 2 is less than num, increment
  92. if ((num % x) == 0) {// if the modulo of num and x is 0 set prime to false
  93. return false;
  94. }
  95. }
  96. return true;
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement