Computer Science, asked by sneha413639, 4 months ago

Please answer my question. ​

Attachments:

Answers

Answered by Anonymous
2

Answer:

YOUR ANSWER IS IN THE ATTACHMENT.

Attachments:
Answered by udayagrawal49
2

Answer: The required java program is :-

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int num = scan.nextInt();

    scan.close();

    boolean flag = false;

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

        if (num % i == 0) {

            flag = true;

            break;

        }

    }

    if (!flag) {

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

    }

    else {

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

    }

   }

}

Please mark it as Brainliest.


Oreki: A separate method should be employed to check a prime number to construct a readable program.
Nevertheless, it's good answer!
udayagrawal49: Yeah, you are right... I will take care of it from next time.
Similar questions