Commit 4b0594c0 authored by Arsam Ali's avatar Arsam Ali

exercise 6

parent 560ababb
......@@ -2,19 +2,26 @@ package Task2;
public class IsPrimeNumber {
public static void main(String[] args) {
int countPrimes = 0;
int count = 0;
for (int i = 2; i < 10000; i++) {
if (isPrime(i)) countPrimes++;
if (isPrime(i)) {
count++;
}
}
System.out.println("Number of prime numbers less than 10000: " + countPrimes);
System.out.println("Number of prime numbers less than 10000: " + count);
}
public static boolean isPrime(int number) {
return number > 1 && java.math.BigInteger.valueOf(number).isProbablePrime(50);
private static boolean isPrime(int number) {
if (number <= 1) {
return false;
}
for (int j = 2; j <= Math.sqrt(number); j++) {
if (number % j == 0) {
return false;
}
}
return true;
}
}
......@@ -6,11 +6,12 @@ public class SeriesComputation {
System.out.println("----------");
for (int a = 1; a <= 20; a++) {
double m = 0; // Initialize m within the loop for clarity
double m = 0;
for (int j = 1; j <= a; j++) {
m += j / (double) (j + 1); // Cast to double for accuracy
m += j / (j + 1.0); // Using double directly
}
System.out.printf("%d\t%.4f\n", a, m);
System.out.println(a + "\t" + String.format("%.4f", m)); // Printing with specified decimal places
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment