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
MrMuchimi
3 years ago
14

Write a function name isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or fals

e otherwise. Demonstrate the function in a complete program that prompts for a number and indicates whether or not it is prime.
Computers and Technology
1 answer:
pishuonlain [190]3 years ago
8 0

Answer:

public static boolean isPrime(int number)

   {

       if(number<1)

           return false;

       else if (number == 1||number ==2 ||number==3)

       {

           return true;

       }

       else

       {

           for(int i=2; i<number; i++)

           {

               if(number%i==0)

                   return false;

           }

           return true;

       }

   }

The complete program is given in the explanation section

Explanation:

import java.util.Scanner;

public class PrimeNumber {

   public static boolean isPrime(int number)

   {

       if(number<1)

           return false;

       else if (number == 1||number ==2 ||number==3)

       {

           return true;

       }

       else

       {

           for(int i=2; i<number; i++)

           {

               if(number%i==0)

                   return false;

           }

           return true;

       }

   }

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter a number to check if it is Prime");

       int num = in.nextInt();

       if(isPrime(num)){

           System.out.println("The number "+num+" is a prime number");

       }

       else {

           System.out.println("The number "+num+" is NOT a prime number");

       }

   }

}

Prime numbers are numbers divisible only by themselves and 1 Examples are: (2, 3, 5, 7, 11)

You might be interested in
Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline() print(line) _________
aleksandrvk [35]

Answer:

The answer is "except IOError:"

Explanation:

It is part of the exception handling, that stands for input/ output operation fails, this exception aeries when we attempting to access an anti-existent file, in the program so, it will give the program related errors.

  • This type of error is handled in the try block, it also allows you to prepare the deal with the exceptional block.  
  • It also helps you to hide the bugs by using code, if you handle an unexpected error.
6 0
3 years ago
Please Help ASAP!!
Maurinko [17]

Answer:

in the page layout view

Explanation:

7 0
4 years ago
Read 2 more answers
Network layer protocols specify the _______ structure and processing used to carry data between hosts.
kari74 [83]

Network layer protocols specify the  <u>packet structure</u> and processing used to carry data between hosts.

<h3>What is the Network layer protocols  about?</h3>

The header, payload, as well as the trailer of a network packet are its three component pieces. The underlying network architecture or protocol employed determines the format and size of a network packet. A network packet resembles a package in concept.

Therefore, Network layer protocols define the packet format and processing needed to transfer data from one host to another host, in contrast to the Transmission layer (OSI Layer 4), which controls the data transport between the programs operating on each end computer.

Learn more about Network layer from

brainly.com/question/14476736
#SPJ1

3 0
1 year ago
Which of the following statements are TRUE about credit cards? I. When you use a credit card, the money comes directly out of yo
Svetllana [295]

i think it is 1. becuase it can be.

4 0
3 years ago
Which type of software is created and updated by a worldwide community of programmers and is available for​ free?
Ede4ka [16]
Open source is created and updated by a worldwide community of programmers and is available for​ free. Many students are in luck, as they can easily study publicly accessible codes and have a possibility to make better software. It also has lots of advantages, such as getting <span>high-quality results when the source code is passed around, tested and fixed.The most important thing - it<span> is a valuable learning opportunity for programmers and opportunity to improve their skills.</span></span>
5 0
4 years ago
Other questions:
  • What considerations have to be kept in mind with JPEG
    10·1 answer
  • A bus topology network is most often deployed as a peer-to-peer network. <br> a. True <br> b. False
    7·1 answer
  • Of which of the following devices are point, drag, and click actions?
    15·1 answer
  • You can't get close enough to the facility interior to launch an evil twin attack against its wireless clients; in fact, you hav
    11·1 answer
  • Your employer is opening a new location, and the IT director has assigned you the task of calculating the subnet numbers for the
    14·1 answer
  • Write a parent program to fork(2) n processes where n is passed tothe program on the command line, and n can be from 1 to 10. Al
    12·1 answer
  • Consider the following schema for customer: (id, name, street, city, state, zip, phone), in which customers are uniquely determi
    10·1 answer
  • TP1. लेखा अभिलेखको अर्थ उल्लेख गर्नुहोस् । (State the mea
    15·1 answer
  • An optical fibre has an attenuation of 0.3 dB/km. If a laser launches an optical power level of PIN (mW) into 35 km length of th
    8·1 answer
  • Write the two features of a mouse.​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!