extras: add P16-P23, P25

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-06-07 03:37:31 +05:30
parent 14898356a8
commit cc83093210
9 changed files with 153 additions and 0 deletions

25
P22.java Normal file
View File

@@ -0,0 +1,25 @@
import java.util.Scanner;
public class P22 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = scanner.nextInt();
System.out.println(n + " is " + (prime(n) ? "" : "not ") + "a prime number.");
scanner.close();
}
public static boolean prime(int number) {
if (number <= 1)
return false;
for (int i = 2; i <= Math.sqrt(number); i++)
if (number % i == 0)
return false;
return true;
}
}