here is the 1st year prime program i had to write in java. super simple, hopefully this helps

Code:

public class Prime {
private void Prime(int number){
// lets the user know that the number was valid and it is calculating primes
System.out.println(number + " accepted! Calculating Primes...");
// loop through the numbers from 1 to final number (specified by user)
for(int c = 1;c <= number; c++){
// pass the number of the loop value to findPrime
if(findPrime(c)){
// if findPrime is true, it spits this out
System.out.println(" "+ c + " is prime!");
}
}
}
private boolean findPrime(int number){
// variable delcaration
int divisor = 2; // 1st point to start for prime numbers since the only prime even number is 2
boolean isPrime = true; // needs to be true to allow the while loop to start
// while the test number is still prime, and the divisor is half of the test number
while((isPrime) && (divisor <= number / 2)){
// checks to see if there is a remainder
if(number % divisor == 0){
// if there is, break the while loop by turning isPrime to false
isPrime = false;
}else{
// otherwise increment divisor to try the next number in the set
divisor++;
}
}
// returns if the test number was prime or not
return isPrime;
}
public static void main(String[] args) {
// Checks to see if the number inputed is really a valid Integer (whole number)
Prime prime = new Prime();
try{
// if it is, start the rest of the program
prime.Prime(Integer.parseInt(args[0]));
}catch(NumberFormatException nfe){
// if it isnt, throw a NumberFormatException error
System.out.println("Error: " + args[0] + " is not a valid whole number! \n Please Try Again!");
}
}
}