I am a beginner to java.And i am trying to print 2,3,5,7,11,13,17,19
This is my thought process.the above numbers i want to print are prime numbers which means they can only be divided by themselves or the value 1.So i will need to have a condition which is if(i%i==0 || %1==0){
import java.util.*;
public class PrimePrinter{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.print("Enter num> ");
int input=sc.nextInt();
for(int i=2;i<=19;i++){
if(i%i==0&&i%1==0){
System.out.print(i);
}else {
System.out.print(",");
}
}
}
}
I try to think through my codes but i wonder why it will print out 2,3,4,5...and up till 19 when i already have a condition.I will appreciate if someone will give me hints for me to work out instead of posting the solutions.