Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This project is to determine if a phone number is a prime number. If the number

ID: 3633496 • Letter: T

Question

This project is to determine if a phone number is a prime number. If the number is a prime number then print a message to that effect. If the number is not a prime number then print the prime factors of the number. The program asks the user to enter the 7 digit phone number, or gives the user an option to exit. Allow the user to continue entering numbers for as long as he or she wishes. The phone number is 7 digits long (Ex: 7069456)

Explanation / Answer

import java.util.*; class CheckPrime{ static boolean isPrime(long number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1){ if ((number!=i) && (number%i==0)){ isPrime=false; break; } else if (!isPrime) isPrime=true; --i; } return isPrime; } public static void main(String[] args){ Scanner input=new Scanner(System.in); int menu = 0; boolean quit = false; System.out.println("1. Check"); System.out.println("2. Exit"); do{ System.out.print("Please enter your choice: "); menu = input.nextInt(); System.out.println(); switch(menu) { case 1: System.out.println("Enter number to check: "); long num=input.nextLong(); if(isPrime(num)){ System.out.println("Hello"); } else{ System.out.println("Factors are:"); for(int i=1;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote