Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Allow the user to specify the upper limit. Either allow the user to specify the

ID: 3565468 • Letter: A

Question

Allow the user to specify the upper limit.

Either allow the user to specify the number of trials, or define a (reasonable) CONSTANT in the program.

Use this design to help make the program:

Write a program that compares the theoretical probability of choosing a prime number within a specified range with the experimental probability of choosing a prime number in the same range. Experimental probability is determined by performing an appropriate number of trials! Allow the user to specify the upper limit. Either allow the user to specify the number of trials, or define a (reasonable) CONSTANT in the program. Use this design to help make the program:

Explanation / Answer

import java.util.Scanner;

//perfectly working

public class NPrimes
{
public static void main(String[] args)
{
System.out.println("enter no. of primes want:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
//int n1=sc.nextInt();
int p=3;
int c=1;
int i,f=1;
if(n>0)
{
   System.out.println("2");
}
while(c<n)
{
   i=2;f=1;
   while(f>0)
   {
       if(p%i!=0)
       {
           i++;
           if(i==p)
           {
               System.out.println(p);
               f=0;
               c++;
               p++;
           }
           else
           {
               f=1;
               continue;
           }
       }
           else
           {
               p++;
               f=0;
           }
       }
  
}


}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote