Math, asked by baibhavdas26, 2 months ago

write a program in java to display all the three digit prime number​

Answers

Answered by pushkardigraskar2005
1

Answer:

//Program to print all prime numbers from 100 to 999.

class abc{

public static void main (String ar []){

for(int I=100;I<=999;I++){

int c=0;

for(int j=1;j<=I;j++)

if(i%j==0)

c++;

if(c==2)

System.out.println(I+" is a prime number");}}}

Logic:

  •    Run I loop from 100 to 999
  •    Run j loop from 1 to I
  •    count all the factors of value of variable I
  •    check if I is a prime number or not (c==2)
  •    if yes, print that number

Hope this will help you.

Similar questions