Computer Science, asked by sabina98yesmin, 7 months ago

4. Write a java program that will show the total number of Primes between 2 numbers given by the user.

The java program will create 3 Threads and each Thread will calculate the total of Prime numbers of,

between the allocated range to it. Main Thread will sum-up the subtotals given by the Threads.

Sample Input:

1 20

Output:

8

Hints:

a) Create a Main program

b) Take 2 integers as input from user – example: 1 20

c) Split the range into 3 groups – example: (a) 1 – 7, (b) 8 – 14, (c) 15 – 20

d) Create 3 Threads and provide them a, b and c splits correspondingly

e) Each Thread will calculate the subtotal of number of Primes within the given range

f) Main program will add all the subtotal returned by the Threads

g) Output the grand total count – example: 8​

Attachments:

Answers

Answered by mamtameena001898
2

Answer:

b

Explanation:

i don't no friends. sorry

Answered by arshaarunsl
0

Answer:

import java.util.Scanner;

class Main {

public static void main(String args[]) {

int first, last, and flag = 0, I and j;

Scanner scanner = new Scanner(System.in);

System.out.print("\nEnter the lower bound : ");

 first = scanner.nextInt();

 System.out.print("\nEnter the upper bound : ");

 last = scanner.nextInt();

The prime numbers between the entered limits are:," prints System.out.println.

int x = 0;

for (i = first; i <= last; i++) {

for (j = 2; j < i; j++) {

if (i % j == 0) {

         flag = 0;

         break;

       } else {

         flag = 1;

       }

     }

     if (flag == 1) {

       x++;

       System.out.println(i + " ");

     }

   }

   System.out.println("Total number of prime numbers between " + first + " and " + last + " are " + x);

 }

}

#SPJ2

Similar questions