Computer Science, asked by rajvishah0106, 8 months ago

wap to display prime numbers till 30?​

Answers

Answered by mohitsingh3852
15

Answer:

in java

Explanation:

class PrimeNumbers

{

public static void main (String[] args)

{

int i =0;

int num =0;

//Empty String

String primeNumbers = "";

for (i = 1; i <= 30; 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 till 30 are :");

System.out.println(primeNumbers);

}

}

mark me as brainliest

Similar questions