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
Computer forensics is practiced _____. A. Only by specially trained government and law-enforcement personnel B. By many organiza
laiz [17]

Answer:

Option B is the correct answer.

<h3>Computer forensics is practiced by many organizations, including public- and private-sector organizations such as hospitals, law enforcement, and businesses. </h3><h3 />

Explanation:

Computer forensics can be defined as a branch of digital forensics that deals with the evidences and and proofs found on all digital storage media such as computers.

It is basically a step for enhancing security bases of communication. Therefore it is mainly used by law-enforcement personnel but it can also be practiced by other institutions for the purpose of self security.

<h3>I hope it will help you!</h3>
4 0
3 years ago
Did the first generation of computers use microprocessors.
Katena32 [7]

no they used standard 8088 Intel processors

hope this helps

8 0
2 years ago
Read 2 more answers
Andrew is researching a new operating system for the computers at his workplace. His boss wants the computers to be able to conn
Bumek [7]

Answer:

Windows 8.1 Core

Explanation:

In this particular example, we're going to use Windows 8.1 Core, is the most basic of the window's family, in this case, only we need an OS to connect the hardware with the cloud computing for security and is not necessary another license, in addition, Windows 8.1 core is easiest to use, is so friendly with the user.

6 0
3 years ago
. What is automated testing?
shepuryov [24]

Answer: Automated testing is testing of the software by the means of automation by using special tools .These software tools are responsible for the testing of the execution process , functioning and comparing the achieved result with actual result.

It is helps in achieving the accuracy as compared with manual testing and also also function without any human interruption.It produces the test scripts that can be re-used.

8 0
4 years ago
Enter an input statement using the input function at the shell prompt. When the prompt asks you for input, enter a number. Then,
Pavel [41]

Answer:

<u>Explanation:</u>

An input statement using the input function at the shell prompt is as follows:

If a prompt asks for a input, a number is to be added

num = input ('Number: ')

num = num + 1

print(num)

Explanation of results: This gives error at line num= num + 1 as cannot convert int object to str implicitly

8 0
3 years ago
Other questions:
  • To join two or more objects to make a larger whole is to _____________ them.
    11·2 answers
  • 6 external parts or peripherals of a computer system and identify which are output and which are input devices.
    5·1 answer
  • How would Microsoft Word inform you of the error in the sentence below? (Tip: The error is in bold.)
    7·1 answer
  • Mr chen xi is a vedio maker in singapore . He had created 14GB vedio file for his customer is united states . Name and describe
    14·1 answer
  • For window 7 explain the steps you will use to find the available program you will list.
    13·1 answer
  • 2.2-2 Consider sorting numbers stored in array by first finding the smallest element n A of and exchanging it with the element i
    11·1 answer
  • Give fields descriptive so that you can easily identify them when you view or edit records.
    13·1 answer
  • What is fair use?
    15·2 answers
  • I still haven't figured out how to award someone branliest will someone help me? If you explain to me how to do it i will do awa
    14·1 answer
  • What physical disk oriented performance counter should be used to determine the number of requests waiting to be processed by a
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!