Here's an example of a program that does what you need only in a sligthtly twisted way. 

This program properly produces the factorization of any odd non-prime number. 

It further identifies the odd primes. 

It declares all the even numbers non-primes. 

The program illustrates the use of do-while, break and continue. 

-bash-4.1$ cat Ten.java
import java.util.*;

class Ten {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    do { // do while loop executes the body first then checks the condition at the end
      System.out.print("Enter: ");
      String number = s.nextLine(); // hopefully a number, for now just a String
      if (number.equals("bye")) break; // break this loop if they want to leave
      int n = Integer.parseInt(number); // if not the keyword it better be a number so parse it
      if (n % 2 == 0 && n > 2) { // easy way to discard this as a non-prime
        System.out.println( n + " is not a prime number because it is even." );
        continue; // resume the loop, that is, get a new number
      }
      String divisors = ""; // collect the divisors here (if any)
      for (int i = 2; i <= n; i = i + 1) { // note the termination condition for the loop
        while (n % i == 0) { // take all divisors with this value out of the number
          n = n / i;
          divisors += i + " "; // add them one by one to the answer
        }
      }
      if (number.contains(divisors.trim())) System.out.println( number + " is a prime number." );
      else System.out.println( number + " not a prime number, prime factorization: " + divisors );
    } while (true); // infinite loop if we didn't break inside...
  }
}
-bash-4.1$ javac Ten.java
-bash-4.1$ java Ten
Enter: 405
405 not a prime number, prime factorization: 3 3 3 3 5
Enter: 45
45 not a prime number, prime factorization: 3 3 5
Enter: 43
43 is a prime number.
Enter: 1
1 is a prime number.
Enter: 2
2 is a prime number.
Enter: 3
3 is a prime number.
Enter: 4
4 is not a prime number because it is even.
Enter: 5
5 is a prime number.
Enter: 21
21 not a prime number, prime factorization: 3 7
Enter: 49
49 not a prime number, prime factorization: 7 7
Enter: 23
23 is a prime number.
Enter: bye
-bash-4.1$