Computer Science, asked by renatosp10, 10 months ago

QUESTION 3
Write a Java program that finds the first 50 prime numbers. You will need a method to test if the number is prime and a method to print the prime numbers. Your program should have the following methods.
public static void main(String[] args)
public static void printPrimeNumbers(int numberOfPrimes)
public static boolean isPrime(int number)
Console Output
The first 50 prime numbers are
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229

Answers

Answered by rohanpawar10906
1

Answer:

he number which is only divisible by itself and 1 is known as prime number. For example 2, 3, 5, 7…are prime numbers. Here we will see two programs: 1) First program will print the prime numbers between 1 and 100 2) Second program takes the value of n (entered by user) and prints the prime numbers between 1 and n. If you are looking for a program that checks whether the entered number is prime or not then see: Java Program to check prime number.

Program to display the prime numbers from 1 to 100

It will display the prime numbers between 1 and 100.

class PrimeNumbers

{

public static void main (String[] args)

{

int i =0;

int num =0;

//Empty String

String primeNumbers = "";

for (i = 1; i <= 100; i++)

{

int counter=0;

for(num =i; num>=1; num--)

{

if(i%num==0)

{

counter = counter + 1;

}

}

if (counter ==2)

{

//Appended the Prime number to the String

primeNumbers = primeNumbers + i + " ";

}

}

System.out.println("Prime numbers from 1 to 100 are :");

System.out.println(primeNumbers);

}

}

Output:

please mark as brainlest answer of

Answered by mexlollbroo
0

So the neighborhood of the experiment is to be able to get some more issues and get it now as a part is that we can you send me the link in your new here is the same as the same as physics and the guidelines is a

Similar questions