Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. public class MathLab04st
  7. {
  8. public static int steve = 0;
  9. public static int numRows;
  10. public static int numCols;
  11. public static void main(String args[])
  12. {
  13. // This main method needs additions for the 100 point version.
  14. Scanner input = new Scanner(System.in);
  15. System.out.print("Enter the number bounds --> ");
  16. numCols = input.nextInt() ;
  17. System.out.println("\nMathLab04\n");
  18. final int MAX = 100;
  19. boolean primes[];
  20. primes = new boolean[MAX];
  21. computePrimes(primes);
  22. displayPrimes(primes);
  23. }
  24.  
  25. public static void computePrimes(boolean primes[])
  26. {
  27. System.out.println("\nCOMPUTING PRIME NUMBERS");
  28.  
  29. }
  30.  
  31. public static void displayPrimes(boolean primes[])
  32. {
  33. System.out.println("\n\nPRIMES BETWEEN 1 AND "+ primes.length);
  34. System.out.println();
  35.  
  36. DecimalFormat fourDigits = new DecimalFormat("0000");
  37.  
  38.  
  39. int k = 0;
  40. long matrix[][] = new long[numRows][numCols];
  41. for (int r = 0; r < numRows; r++)
  42. {
  43. if (steve == numCols)
  44. {
  45. break;
  46. }
  47. for (int c = 0; c < numCols; c++)
  48. {
  49. boolean check = false;
  50. do
  51. {
  52. if (steve == numCols)
  53. {
  54. break;
  55. }
  56.  
  57. if (k == 1)
  58. {
  59. matrix[r][c] = k;
  60. check = true;
  61. steve++;
  62. }
  63.  
  64. else if (k % 2 == 0)
  65. {
  66. if (k == 2)
  67. {
  68. matrix[r][c] = k;
  69. check = true;
  70. }
  71. else
  72. {
  73. k++;
  74. }
  75. steve++;
  76. }
  77. else if (k % 3 == 0)
  78. {
  79. if (k == 3)
  80. {
  81. matrix[r][c] = k;
  82. check = true;
  83. }
  84. else
  85. {
  86. k++;
  87. }
  88. steve++;
  89. }
  90. else if (k % 5 == 0)
  91. {
  92. if (k == 5)
  93. {
  94. matrix[r][c] = k;
  95. check = true;
  96. }
  97. else
  98. {
  99. k++;
  100. }
  101. steve++;
  102. }
  103. else if (k % 7 == 0)
  104. {
  105. if (k == 7)
  106. {
  107. matrix[r][c] = k;
  108. check = true;
  109. }
  110. else
  111. {
  112. k++;
  113. }
  114. steve++;
  115. }
  116. else
  117. {
  118. matrix[r][c] = k;
  119. check = true;
  120. steve++;
  121. }
  122. }
  123. while(check == false);
  124. if (steve == numCols)
  125. {
  126. break;
  127. }
  128. k++;
  129. }
  130. }
  131. System.out.println();
  132.  
  133. //numCols = 15;
  134. for (int r = 0; r < numRows; r++)
  135. {
  136. for (int c = 0; c < numCols; c++)
  137. {
  138. if(matrix [r][c] != 0)
  139. {
  140. System.out.print(fourDigits.format(matrix[r][c]) + " ");
  141. }
  142.  
  143. }
  144. System.out.println();
  145. }
  146. }
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement