How to print Prime numbers in Java or how to check if a number is prime or not is classical Java programming questions, mostly taught in Java programming courses. A number is called prime number if its not divisible by any number other than 1 or itself and you can use this logic to check whether a number is prime or not. This program is slightly difficult than printing even or odd number which are relatively easier Java exercises. This Simple Java program print prime number starting from 1 to 100 or any specified number. It also has a method which checks if a number is prime or not.
This Java tutorial is in conjunction with my earlier tutorial for beginners like How to set Path in Java on windows and Unix , Java Program to reverse String in Java with recursion and recently how to read file in Java etc, if you haven’t read them you may find them useful.