I am working on a code for loops where I need to list all the prime numbers between value A(number person enters lets say 101) and value b(the other number a person enters 200) and I am totally lost. here is what I have so far.   import java.util.Scanner; public class PrimeNumber { public static void main(String[] args) { Scanner input = new Scanner(System.in); final int NUMBER_OF_PRIMES = 21; final int NUMBER_OF_PRIMES_PER_LINE = 5; int count = 0 ; int number = 2; System.out.println("enter a number value for a: "); int nbr1 = input.nextInt();   System.out.println("Enter a number for b: "); int nbr2= input.nextInt();   // Repeatedly find prime numbers while (count < NUMBER_OF_PRIMES) { boolean isPrime = true; for (int divisor = 2; divisor <= number / 2; divisor++)  if (number % divisor == 0) { isPrime = false; break; }   if (isPrime) { count++; if (count % NUMBER_OF_PRIMES_PER_LINE == 0) { System.out.println(number); } else { System.out.print(number + " "); } } number++; } // End while } }  // End main }   I want to get the prime numbers between 101 and 200 but I keep getting the prime between 2 and 73    Output: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73

Question

I am working on a code for loops where I need to list all the prime numbers between value A(number person enters lets say 101) and value b(the other number a person enters 200) and I am totally lost. here is what I have so far.

 

import java.util.Scanner;

public class PrimeNumber

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

final int NUMBER_OF_PRIMES = 21;

final int NUMBER_OF_PRIMES_PER_LINE = 5;

int count = 0 ;

int number = 2;

System.out.println("enter a number value for a: ");

int nbr1 = input.nextInt();

 

System.out.println("Enter a number for b: ");

int nbr2= input.nextInt();

 

// Repeatedly find prime numbers

while (count < NUMBER_OF_PRIMES) {

boolean isPrime = true;

for (int divisor = 2; divisor <= number / 2; divisor++) 

if (number % divisor == 0) {

isPrime = false;

break; }

 

if (isPrime) { count++;

if (count % NUMBER_OF_PRIMES_PER_LINE == 0) {

System.out.println(number); }

else {

System.out.print(number + " "); }

}

number++; } // End while

}

}

 // End main }

 

I want to get the prime numbers between 101 and 200 but I keep getting the prime between 2 and 73 

 

Output:

2 3 5 7 11

13 17 19 23 29

31 37 41 43 47

53 59 61 67 71

73 

Expert Answer

1 Rating

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.

Related Computer Science Q&A

Find answers to questions asked by student like you

Q: Part-1(Java) Create a doubly linked list based DeQueDLL class that implements the DequeInterface. T...

A: Assuming the DLLNode class with given methods (use methods of your implementation of DLLNode class):...

Q: How would I go about writing the code in the problem in the picture?

A: Program AlgorithmCreate a class Prime_Numbers and define the main() function.Initialize the required...

Q: I need help tackling this program:     Write a C++ console application that allows your user to ente...

A: For solving this problem following variables and data type are used to execute this file :1.Variable...

Q: Evaluate cloud computing in relation to each of these four (4) criteria Dependable Manageable Adapta...

A: DescriptionEvaluating cloud computing in relation to the following four criteria’s:DependableDependa...

Q: How do I write 1 cup = 8 ounces and then use that to find the total ounces of milk- 2cups +  flour 2...

A: 1 cup is equal to 8 ounces.The total cup is given as 2-cups of milk, 2.66 cups of flour, and 1.5 cup...

Q: A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 servi...

A: A C++ program to display the number of calories consumed for the cookies that he/she ate is given be...

Q: I need help with this C++ problem.    Assume that a binary search function is searching for a value ...

A: Binary search: - It is a technique used to search an element in a sorted array.It is also known as h...

Q: Vectors Write three statements to print the first three elements of vector runTimes. Follow each wit...

A: Program DescriptionThe program prompts the user to input 5 numbers to populate the vectorIt tests th...

Q: In C++ programming. Below is the UAH_sample.txt The University of Alabama in Huntsville was founded ...

A: Since the program is quite complex we are answering only the first part due to lack of space, it is ...