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
creativ13 [48]
3 years ago
8

Write a recursive function to determine if a number is prime.

Computers and Technology
1 answer:
Darya [45]3 years ago
6 0

Answer:

Follows are the code to find the prime number:

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

public class Main//defining a class

{  

public static boolean Prime(int x, int j)//defining a method isPrime    

   {  

       if (x<= 2) //use if block to check x less than equal to 2

           return (x== 2) ? true : false; //use bitwise operator to return value  

       if (x%j == 0) //use if to check x%j equal to 0

           return false;//return false value  

       if (j*j > x)//defining if that check i square value greater than n  

           return true; //return true value

       return Prime(x, j+1); //callling recursive method

   }  

   public static void main(String[] as)//main method  

   {  

       int n; //defining integer variable

       Scanner oxc=new Scanner(System.in);//creating Scanner class object

       n=oxc.nextInt();//input value

       if (Prime(n, 2))  //use if block to call isPrime method

           System.out.println("Yes"); //print value  

       else //else block

           System.out.println("No");  //print value  

   }  

}  

Output:

5

Yes

Explanation:

In this code, a static boolean method "Prime" is declared, that accepts two integer variables in its parameter and defines the if block that checks the prime number condition by the recursive method and returns a value true or false. Inside, the main method an integer variable is declared that uses the Scanner class object for input value and passes into the method and prints its value.

You might be interested in
What do we call notes in computer code for the programmer that are ignored by the compiler?.
Lelu [443]

The notes in computer code for the programmer that are ignored by the compiler is called a comment.

<h3>What are codes in programming?</h3>

Codes in programming are specific sequences or sets of instructions that are made for specific programs. They are written in a specific language. They are made to make a human-friendly language. Codes are made after the compiler confirms them.

Comments are written for the document. They tell what the document is for, and how the document is constructed.

Thus, the notes on the computer code for the programmer are called a comment.

To learn more about comments in computer code, refer to the link:

brainly.com/question/18340665

#SPJ4

4 0
2 years ago
Sequential codes may be used to represent complex items or events involving two or more pieces of related data.
katrin2010 [14]

Answer:

The answer is "Option B".

Explanation:

Sequential codes are modules that work toward the solution of a problem that is arranged in a serialized manner. It is also known as serial codes, It is code in which the following two digits differ by a single digit in the binary representation.

  • It helps to decide, which task and how long it will take.
  • It uses communication to provide synchronized and shares resources between tasks.
4 0
4 years ago
A customer states that when she removes the printed pages from her laser printer output tray, the black ink smears all over her
luda_lava [24]

Answer:

B. Fuser unit

Explanation:

Based on the scenario that is being described it can be said that the most likely problem is the Fuser unit. This is a part that plays an important role in the printing process. This unit melts the toner and compresses it in order to leave the impression on the paper with heat. A faulty fuser unit will not compress correctly and leave wet ink on the paper causing it to smear.

7 0
4 years ago
:P 80 points to spare so i guess its free!!!!!!
Naddik [55]

Answer:

Thank you! can i have brainliest please?

Explanation:

5 0
3 years ago
Read 2 more answers
If you want help using drawing, word processing, and e-mail programs, the best place for you to find it is through the Start men
ZanzabumX [31]

Answer:

True

Explanation:

True

5 0
3 years ago
Other questions:
  • Melissa and Sue want to show a presentation to twenty employees using a presentation while using a projector. They learn that th
    12·2 answers
  • What is the first step to creating a PivotTable?
    11·1 answer
  • Print a countdown from n to 1 The function below takes one parameter: an integer (begin). Complete the function so that it print
    8·1 answer
  • A company has its branches spread over five places in a state. It has become difficult for employees to transfer information and
    7·1 answer
  • Which IEEE standards define Wi-Fi technology?
    10·1 answer
  • Which type of NAC agent will be used during the posture assessment before allowing access to the VPN users?
    9·1 answer
  • A write once, read many (worm) disc is a common type of _____.
    6·1 answer
  • What is an Operating System ??
    7·1 answer
  • HELP PLSSS I WILL MARK U!!!!
    10·2 answers
  • Which family does Ms word 2007 belongs to?​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!