Question

A prime number is an integer greater than 1 that is evenly divisible by only 1...

A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Create a PrimeNumber application that prompts the user for a number and then displays a message indicating whether the number is prime or not. Hint: The % operator can be used to determine if one number is evenly divisible by another. ( Java programing )

Homework Answers

Answer #1
//PrimeNumberCheck.java
import java.util.Scanner;
public class PrimeNumberCheck {
    private static boolean isPrime(int n) {
        if(n%2!=0 && n%3!=0){
            return true;
        }
        else{
            return false;
        }
    }

    public static void main(String args[]) {
        int n;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        n = scanner.nextInt();
        if(isPrime(n)){
            System.out.println(n+" is a prime");
        }
        else{
            System.out.println(n+" is a not prime");
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
A Harshad number (or a Niven number) is a number that is evenly divisible by the...
A Harshad number (or a Niven number) is a number that is evenly divisible by the sum of its digits. An example is 18 (1+8=9, 18%9 = 0). Write a function called isHarshad(num) that takes an integer as an argument and returns True if the number is a Harshad number and False if it is not. Then, use this function to create a list of all of the Harshad numbers in the first 500 natural numbers.
Write the following in C: 2. An integer is said to be prime if it is...
Write the following in C: 2. An integer is said to be prime if it is divisible by only 1 and itself. Write a function called prime() that takes in one integer number, and returns 1 (true) if the number is prime and 0 (false) otherwise. Write a program to generate six random numbers between 1 to 100 and calls function prime() on each one to determine if it is prime or not.
Activity 6.6. (a) A positive integer that is greater than 11 and not prime is called...
Activity 6.6. (a) A positive integer that is greater than 11 and not prime is called composite. Write a technical definition for the concept of composite number with a similar level of detail as in the “more complete” definition of prime number. Note. A number is called prime if its only divisors are 1 and itself. This definition has some hidden parts: a more complete definition would be as follows. A number is called prime if it is an integer,...
JAVA a. An integer is a "Lucky Number" if it is divisible by 7 or is...
JAVA a. An integer is a "Lucky Number" if it is divisible by 7 or is divisible by 11 and it is in the range 1000 through 4000. Write a Boolean expression that is true if and only if myNum (an int variable) contains a Lucky Number. b. Let a and b represent the length and the width of a rectangle. The length of the diagonal of the rectangle can be calculated by the following mathematical expression. diagonalLength = squareRoot(a...
4. Prove that if p is a prime number greater than 3, then p is of...
4. Prove that if p is a prime number greater than 3, then p is of the form 3k + 1 or 3k + 2. 5. Prove that if p is a prime number, then n √p is irrational for every integer n ≥ 2. 6. Prove or disprove that 3 is the only prime number of the form n2 −1. 7. Prove that if a is a positive integer of the form 3n+2, then at least one prime divisor...
Each natural number greater than 1 is either a prime number or is a product of...
Each natural number greater than 1 is either a prime number or is a product of prime numbers
1. Prove that an integer a is divisible by 5 if and only if a2 is...
1. Prove that an integer a is divisible by 5 if and only if a2 is divisible by 5. 2. Deduce that 98765432 is not a perfect square. Hint: You can use any theorem/proposition or whatever was proved in class. 3. Prove that for all integers n,a,b and c, if n | (a−b) and n | (b−c) then n | (a−c). 4. Prove that for any two consecutive integers, n and n + 1 we have that gcd(n,n + 1)...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT