Computer Science, asked by piyushanand63, 11 months ago

Write a programmer to ask a question in java

Answers

Answered by Anonymous
1

Answer:

-3

2

I've already made it so that it will tell whether the input from the user is a prime number or not a prime number but now I have to make it so that it will ask the user if he/she wants to check another number and wait for the user to enter "Y" or "y" as yes, "n" or "N" as no. If yes, repeat the three steps. If no, exit the program. For all other letters, reject ti and ask the user to enter only "y" or "n".

import java.util.*;  // importing package util

public class Prime

{

   public static void main (String args[])

   {

       int num,count=0;

       Scanner scan = new Scanner(System.in); //scanner for input

       System.out.print("Enter any number : ");

       num = scan.nextInt();

       for(int i=2; i <= (num/2); i++)  

       {

           if((num % i) == 0)

           {

               count++;

               break;

           }

       }

       if((count==0) && (num!= 1))

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

       else

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

   }

}

Explanation:

Similar questions