Java Beginners Learn from Naruto

Naruto7

Well-known member
  • Dec 13, 2011
    4,311
    1,867
    113
    ~අනන්තයෙ~
    I thought of Sharing my knowledge which i got from IJTS (the BEST COLLEGE FOR JAVA) to beginners. not for experts.So if you have any questions regarding basic stuff post here so we can advance step by step.

    First ill post a program where it finds whether the number is a prime or not and tells a num which divides it.Just go through it n try to learn whats going through.It will help you to understand basic concepts.


    import java.util.*;

    public class PrimeNum{
    public static void main(String args[]){
    Scanner x=new Scanner(System.in);
    System.out.println("Enter the number : ");
    int y=x.nextInt();
    int i;
    for( i=2;i<y;i++){
    int z=y%i;
    if(z==0){
    System.out.println("Number is not prime");
    System.out.println(y+" Divide by "+i);
    i=y;
    }

    }if(i==y || y==1) System.out.println("Number is prime");
    }
    }