Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class MathLab04st
- {
- public static int steve = 0;
- public static int numRows;
- public static int numCols;
- public static void main(String args[])
- {
- // This main method needs additions for the 100 point version.
- Scanner input = new Scanner(System.in);
- System.out.print("Enter the number bounds --> ");
- numCols = input.nextInt() ;
- System.out.println("\nMathLab04\n");
- final int MAX = 100;
- boolean primes[];
- primes = new boolean[MAX];
- computePrimes(primes);
- displayPrimes(primes);
- }
- public static void computePrimes(boolean primes[])
- {
- System.out.println("\nCOMPUTING PRIME NUMBERS");
- }
- public static void displayPrimes(boolean primes[])
- {
- System.out.println("\n\nPRIMES BETWEEN 1 AND "+ primes.length);
- System.out.println();
- DecimalFormat fourDigits = new DecimalFormat("0000");
- int k = 0;
- long matrix[][] = new long[numRows][numCols];
- for (int r = 0; r < numRows; r++)
- {
- if (steve == numCols)
- {
- break;
- }
- for (int c = 0; c < numCols; c++)
- {
- boolean check = false;
- do
- {
- if (steve == numCols)
- {
- break;
- }
- if (k == 1)
- {
- matrix[r][c] = k;
- check = true;
- steve++;
- }
- else if (k % 2 == 0)
- {
- if (k == 2)
- {
- matrix[r][c] = k;
- check = true;
- }
- else
- {
- k++;
- }
- steve++;
- }
- else if (k % 3 == 0)
- {
- if (k == 3)
- {
- matrix[r][c] = k;
- check = true;
- }
- else
- {
- k++;
- }
- steve++;
- }
- else if (k % 5 == 0)
- {
- if (k == 5)
- {
- matrix[r][c] = k;
- check = true;
- }
- else
- {
- k++;
- }
- steve++;
- }
- else if (k % 7 == 0)
- {
- if (k == 7)
- {
- matrix[r][c] = k;
- check = true;
- }
- else
- {
- k++;
- }
- steve++;
- }
- else
- {
- matrix[r][c] = k;
- check = true;
- steve++;
- }
- }
- while(check == false);
- if (steve == numCols)
- {
- break;
- }
- k++;
- }
- }
- System.out.println();
- //numCols = 15;
- for (int r = 0; r < numRows; r++)
- {
- for (int c = 0; c < numCols; c++)
- {
- if(matrix [r][c] != 0)
- {
- System.out.print(fourDigits.format(matrix[r][c]) + " ");
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement