Question

Design a program in Java that displays all of the prime numbers from 1 through 100....

Design a program in Java that displays all of the prime numbers from 1 through 100. The program should have a loop that calls the isPrime() function.

  • 11 Prime Numbers List (15 points)

Use CONSTANTS to set the maximum number in the table to 100 and the number of entries per row to 5.  

Table of prime numbers from 1 to 100
1 2 3 5 7
11 13 17 19 23
29 31 37 41 43
47 53 59 61 67
71 73 79 83 89
97

Homework Answers

Answer #1
public class PrimeNumbersList {
    public static boolean isPrime(long n){
        for(int i = 2;i<n;i++){
            if(n%i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println("Table of prime numbers from 1 to 100");
        int k = 1;
        for(int i = 1;i<=100;i++){
            if(isPrime(i)) {
                System.out.print(i + " ");
                k++;
            }
            if(k%6==0){
                System.out.println();
                k = 1;
            }
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the below vector x, which you can copy and paste directly into Matlab. The vector...
Consider the below vector x, which you can copy and paste directly into Matlab. The vector contains the final grades for each student in a large linear algebra course. x = [61 52 63 58 66 92 64 55 76 60 70 78 76 73 45 63 97 70 100 76 50 64 42 100 67 81 81 59 68 62 72 99 66 76 81 59 47 84 67 75 63 86 73 44 51 69 48 74 61...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 55000 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
have a java application need to create an application which is able to do some analysis...
have a java application need to create an application which is able to do some analysis on temperature data stored in a data file. You will be given the “temperatures.dat” data file which contains the data you must analyze. The analysis you’ll need to do is: Total number of data points Find coldest temperature Find warmest temperature Find average temperature Find the frequency of each temperature Find the most frequent temperature Find the least frequent temperature All classes must be...
Question 1: Table 1 shows the number of customers visited by a salesman over an 80-week...
Question 1: Table 1 shows the number of customers visited by a salesman over an 80-week period. Table 1: Customers Visited Over an 80-Week Period 68 64 75 82 68 60 62 88 76 93 73 79 88 73 60 93 71 59 85 75 61 65 75 87 74 62 95 78 63 72 66 78 82 75 94 77 69 74 68 60 96 78 89 61 75 95 60 79 83 71 79 62 67 97 78...
Write a program in python that prints the count of all prime numbers between A and...
Write a program in python that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2,...
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all...
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all the prime numbers up to that value. Example: If input parameter is 10, output is "2, 3, 5, 7" If input parameter is 100, output is "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" Write a "tester function" that: Given a specific subset of inputs, tests the...
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
[JAVA] Write a program that prompts the user for an integer and displays if the provided...
[JAVA] Write a program that prompts the user for an integer and displays if the provided integer is a prime number or not. A prime number is a number that is divisible only by 1 and itself. First few prime numbers are 2,3,5,7,11,13 and so on. [using if-statements, and if-else-statement ]
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT