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
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
English,
1 month ago
History,
1 month ago
Social Sciences,
1 month ago
Math,
3 months ago
Math,
3 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago