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
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...
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...
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...
A mathematics achievement test consisting of 100 questions was given to 50 sixth grade students at...
A mathematics achievement test consisting of 100 questions was given to 50 sixth grade students at maple Elementary School. The following data show the number of questions answered correct by each student. 75 48 46 65 71 49 61 51 57 49 84 85 79 85 83 55 69 88 89 55 61 72 64 67 61 77 51 61 68 54 63 94 54 53 71 84 79 75 65 50 45 65 77 71 63 67 57 63...
Prime Numbers) Write a program to calculate and print a list of all prime numbers from...
Prime Numbers) Write a program to calculate and print a list of all prime numbers from 1 to 100. C programming
Using for loops: - write a Java program that adds numbers between 1 to 100 and...
Using for loops: - write a Java program that adds numbers between 1 to 100 and prints the result. - write a Java program that adds odd numbers between 1 to 100 and prints the result - write a Java program that averages even numbers between 5 to 30 and prints the result
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88...
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88 84 5 76 58 6 66 79 7 75 73 8 94 93 9 66 65 10 92 86 11 80 53 12 87 83 13 86 49 14 63 72 15 92 87 16 75 89 17 69 81 18 92 94 19 79 78 20 60 71 21 68 84 22 71 74 23 61 74 24 68 54 25 76 97...
write a C++ program that display a prime numbers between 1 and 100 number. Plase print...
write a C++ program that display a prime numbers between 1 and 100 number. Plase print the remaining primes by “dots” For gexample The output should appear like The prime numbers between 1 and 100 are: 1, 2, 3, 5, 7, .........
Below represent scores on an exam, each entry one score for one student 40 99 59...
Below represent scores on an exam, each entry one score for one student 40 99 59 98 63 63 64 65 67 35 67 67 68 70 71 71 71 46 72 72 60 73 74 74 74 75 97 75 62 76 76 76 76 76 77 57 77 98 77 63 78 78 78 79 79 80 80 80 80 80 81 81 92 81 93 82 82 83 83 83 83 83 83 83 84 84 84...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades and add a linear trendline. What is the​ model? If a student scores 7878 on the​ midterm, what would you predict her grade on the final exam to​ be? Student Midterm Final Exam 1 75 64 2 85 91 3 80 68 4 88 83 5 76 60 6 67 80 7 78 74 8 95 94 9 67 61 10 93 87 11...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT