1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
FinnZ [79.3K]
4 years ago
7

Write a Java program that uses a value-returning method to identify the prime numbers between 2 bounds (input from the user). Th

e method should identify if a number is prime or not. Call it in a loop for all numbers between the 2 bounds and display only prime numbers. Check for errors in input. Note: A number is prime if it is larger than 1 and it is divisible only by 1 and itself (Note: 1 is NOT a prime number) Example: 15 is NOT prime because 15 is divisible by 1, 3, 5, and 15; 19 is prime because 19 is divisible only by 1 and 19. Sample run: How many times to test for prime numbers? -3 Error! Should be positive. Reenter: 3 Enter lower bound/upper bound: 5 3 Error! Lower bound should be larger. Reenter: 3 15 Prime numbers between 3 and 15 are: 3 5 7 11 13 Enter lower bound/upper bound: 2 25 Prime numbers between 2 and 25 are: 2 3 5 7 11 13 17 19 23 Enter lower bound/upper bound: 1 55 Prime numbers between 1 and 55 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53
Computers and Technology
1 answer:
Aleksandr-060686 [28]4 years ago
6 0

Answer:

Following are the program in java programming language  

import java.io.*; // import package

import java.util.*; // import package for input

class Main

// main class  

{

  public static int checker(int n)

  {

      int k=2;

      if(n<=1)

          return 0; // return 0

      if(n==2) // this will return 2

          return 1;

      while(k<n) // loop

      {

          if(n%k==0)

              return 0; // return 0

              k++;

      }

      return 1; // return 1

  }

  public static void main(String args[]) // main methid

  {

      int k1=0,j;// variable declaration

      Scanner input1 =new Scanner(System.in); // creating object of scanner class

      System.out.print("How many times to test for prime numbers?");

      int counting=input1.nextInt(); // read the counting

      if(counting<0) // check the condition if countion is less then 0

      {

          System.out.print("Error! Should be positive.Re-enter: ");

          counting=input1.nextInt(); // taking input

      }

      while(k1<counting)

      {

          System.out.print("\nEnter lower bound and upper bound:");

          int lower=input1.nextInt(); // read the lower bound  

          int upper=input1.nextInt(); // read the upper bond

          if(lower>=upper) // check condition  

          {  

              System.out.print("Error! Lower bound should be larger.Reenter: ");

              lower=input1.nextInt();

              upper=input1.nextInt();

          }

          for(j=lower;j<=upper;j++)

          {

              int result=checker(j); // calling functuion checker

              if(result==1)

              System.out.print(j+" ");  

          }

          k1++;

      }

  }

}    

Output:

How many times to test for prime numbers? 1

Enter lower bound and upper bound:  4

8

5 7

Explanation:

  • In this we create a function "checker" of int datatype which return the corresponding prime number .
  • In the main, we taking the user input of upper and lower bound and checking the corresponding conditions which are already mentioned in the question.
  • Call the checker function in the main method which returns the prime number and finally prints the prime numbers between the lower and upper bound.

You might be interested in
Explain where the “heart” of the station is and what can be found there? I will mark brainlyest! This is for the ISS (Internatio
Annette [7]

Answer:

Zevzda

Explanation:

Check for yourself if you think i'm wrong

7 0
3 years ago
Read 2 more answers
How to you compute for the total room sales​
Furkat [3]

Answer:

[checking question] - Error:

Please give complete/specific questions so more brainies will be able to help you! Check out what makes a great answer/question here: https://faq.brainly.com/hc/en-us/articles/360010136959-Answering-Guidelines ߷

7 0
3 years ago
What types of information should have their sources cited to avoid plagiarism? List at least 3
Sindrei [870]

Answer:

Everything.It doesn't matter the information because there's always a way to plagiarize.No matter what the information, always, ALWAYS, cite the source.

Explanation:

6 0
3 years ago
true or false: the larger your sample size for a survey, the more likely it is that you will draw false conclusions from your in
Alex_Xolod [135]
False. The more people you have the more likely you will have true conclusions...
6 0
3 years ago
Consider the following statements: Statement A: In Duplex transmission, either node can transmit while the other node can receiv
sergij07 [2.7K]

Answer:

<u>d. Statement A is true and Statement B is false</u>

Explanation:

Indeed, when using duplex transmission either node can transmit while the other node can receive data from the network. Also, in half-duplex transmission, both the nodes can transmit as well as receive data.

However, in half-duplex transmission, the nodes <em>cannot </em>transmit and receive data at the same time. Hence, this makes Statement B false, while Statement A is true.

4 0
3 years ago
Other questions:
  • A typical serial cable has
    13·1 answer
  • Who is the primary audience for demonstrations of game prototypes made by the developer?
    8·1 answer
  • What are personal skills? A manner of individual style How a person manages and expresses oneself One's ability to excel at spor
    13·2 answers
  • Which processor family is most likely found on recent gaming laptops (Gaming laptops require a lot of computational power)?
    11·1 answer
  • How many bytes are there in 256 Kbytes?
    6·1 answer
  • Shane is working on a new project for the sales department. The company wants a way to allow the sales force to print orders at
    5·1 answer
  • Write a summary of five things that you learned about CSS. Do not copy and paste the information. Summarize each point in your o
    5·1 answer
  • What is Microsoft marketing ?
    10·1 answer
  • What is the most popular game design engine today
    7·2 answers
  • What does altgr mean on a keyboard.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!