Computer Science, asked by Trived, 3 months ago


using for loop

solve this just using for loop and without using Boolean stuffs.. just normal prime number logic and for loop ​

Attachments:

Answers

Answered by naadhinarayan
1

Answer:

import  java.util.Scanner ;

public class main

{

public static void main()

{

Scanner sc = new Scanner(System.in) ;

sop("enter a number“) ;

int n = sc.nextInt() ;

for(int i = 1 ; i <= 20 ; )

{

int pn = 0 ;

for(int c = 1 ; c<=n ; c++)

{

if(n%c == 0)

{

pn = pn + 1 ;

}

}

if(pn == 1)

{

i++ ;

Sop(n) ;

}

n = n + 1 ;

}

}

}

Explanation:

its simple , use nested for loop

Similar questions