Write a program to print all the 3 digit prime numbers in java
Answers
Answered by
1
Answer:
• Public class prime number
• public static void main (string args) {
• inter i,m=0, flag=0
Answered by
8
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
Similar questions