1.

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

Answer»

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.



Discussion

No Comment Found

Related InterviewSolutions