-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.java
110 lines (93 loc) · 2.7 KB
/
main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 07:00 remaining
// main.java
// created and
// open in
// intellij
// used chat google and intellij
// 04:45 remaining:
/*
* prompt:
* please give a simple version of a prime checker java file which I can then copy into intellij and there I will use the encapsulate button, where intellij will make it into encapsulated form of the program
*
*
* first answer:
* public class PrimeChecker {
public static void main(String[] args) {
int numberToCheck = 17; // Replace with the number you want to check
boolean isPrime = checkPrime(numberToCheck);
if (isPrime) {
System.out.println(numberToCheck + " is a prime number.");
} else {
System.out.println(numberToCheck + " is not a prime number.");
}
}
public static boolean checkPrime(int number) {
if (number <= 1) {
return false;
}
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
}
*
* ######################################
*
* second unencapsulated answer from ChatGPT:
*
* prompt:
* please redo with all in main method no separate checkPrime method
*
* result:
*
* public class PrimeChecker {
public static void main(String[] args) {
int numberToCheck = 17; // Replace with the number you want to check
boolean isPrime = true;
if (numberToCheck <= 1) {
isPrime = false;
} else {
for (int i = 2; i <= Math.sqrt(numberToCheck); i++) {
if (numberToCheck % i == 0) {
isPrime = false;
break;
}
}
}
if (isPrime) {
System.out.println(numberToCheck + " is a prime number.");
} else {
System.out.println(numberToCheck + " is not a prime number.");
}
}
}
* now second result as code
* 02:30 remaining:
*/
public class PrimeChecker {
public static void main(String[] args) {
int numberToCheck = 17; // Replace with the number you want to check
boolean isPrime = true;
if (numberToCheck <= 1) {
isPrime = false;
} else {
for (int i = 2; i <= Math.sqrt(numberToCheck); i++) {
if (numberToCheck % i == 0) {
isPrime = false;
break;
}
}
}
if (isPrime) {
System.out.println(numberToCheck + " is a prime number.");
} else {
System.out.println(numberToCheck + " is not a prime number.");
}
}
}
// +2 min 0041
// end 0039 Friday 08/12/2023
// start 0024 hours Friday 08/12/2023