willieshi232

Untitled

Oct 29th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1.  
  2. 2a.int n = 1;
  3. while (n <= max) {
  4. System.out.println(n);
  5. n++;
  6. }
  7. int total = 25;
  8. 2b.int number = 1;
  9. while (number <= (total / 2)) {
  10. total = total - number;
  11. System.out.println(total + " " + number);
  12. number++;
  13. }
  14. 2c.int i = 1;
  15. while (i <= 2) {
  16. int j = 1;
  17. while (j <= 3) {
  18. int k = 1;
  19. while (k <= 4) {
  20. System.out.print("*");
  21. k++;
  22. }
  23. System.out.print("!");
  24. j++;
  25. }
  26. System.out.println();
  27. i++;
  28. }
  29. 2d.int number = 4;
  30. int count = 1;
  31. while (count <= number) {
  32. System.out.println(number);
  33. number = number / 2;
  34. count++;
  35. }
  36. 4.
  37. 19 , 0
  38. 21, 1
  39. 3 , 4
  40. 5 , 3
  41. 1 , 6
  42. 6.
  43. Random rand = new Random();
  44. int num = rand.nextInt(11);
  45. 8.
  46. 1 11 21 31 41 51 61 71 81 91
  47. 10.
  48. public static int zeroD(int number) {
  49. int count = 0;
  50. do {
  51. if (number % 10 == 0) {
  52. count++;
  53. }
  54. number = number / 10;
  55. } while (number > 0);
  56. return count;
  57. }
  58. 12.
  59. public static void printL(String text) {
  60. if (text.length() > 0) {
  61. System.out.print(text.charAt(0));
  62. for (int i = 1; i < text.length(); i++) {
  63. System.out.print("-" + text.charAt(i));
  64. }
  65. }
  66. 14.
  67. true
  68. true
  69. false
  70. true
  71. true
  72. false
  73. false
  74. true
  75. true
  76. true
  77. true
  78. false
  79. 16.
  80. After it it goes finds a factor once it will go to prime is flase however when it runs it again prime will be reset to true.
  81. public static boolean isPrime(int n) {
  82. boolean prime = true;
  83. for (int i = 2; i < n; i++) {
  84. if (n % i == 0) {
  85. prime = false;
  86. }
  87. }
  88. return prime;
  89. }
  90. 18.
  91. public static boolean startEndSame(String str) {
  92. return str.charAt(0) == str.charAt(str.length() - 1);
  93. }
  94. 20.
  95. 3,1,2,6,15
  96. 22.
  97. !b
  98. (x <= y) || (y <= z)
  99. (x != y) && (x > z)
  100. (x % 2 == 0) || !b
  101. (x / 2 != 13) && !b && (z * 3 != 96)
  102. (z >= x) || (z <= y && x < y)
Advertisement
Add Comment
Please, Sign In to add comment