Java prime numbers


#1

Hello.
I need to help with my homework. Im in blind alley with this. Program should do something like this:
Ask you for a integer and then it prints all his prime numbers from <1 to n>. Its needs to have 2 classes, one for “Testing” and generating. Can someone help to solve this.

Code bellow:
FIRST CLASS
import java.util.Scanner;
public class PrimeNumbersTester {
public static void main(String args) {
Scanner scan = new Scanner(System.in);
System.out.println(“Your number:”);
int number = scan.nextInt();
scan.close();
PrimeNumbers generator = new PrimeNumbers(number);

	System.out.println(generator.nextPrime());
    System.out.println("expected value: 2");
    System.out.println(generator.nextPrime());
    System.out.println("expected value: 3");
    System.out.println(generator.nextPrime());
    System.out.println("expected value: 5");
}

}

NEXT CLASS
public class PrimeNumbers {
private int number;
private int lastPrime;
public PrimeNumbers(int number)
{
this.number = number;
}
public boolean jePrvocislo(int cislo)
{
for (int i = 2; i < cislo; i++)
{
if (cislo % i == 0)
{
return false;
}
}
return true;
}
public int nextPrime()
{
for(int i = lastPrime; lastPrime < number; i++)
{
if(jePrvocislo(i))
{
lastPrime = i;
return i;
}
else
{
i++;
}
return i;
}
return number;
}
}


#2

Unclear what the problem is.

One way to phrase a question is to describe what particular change you’re currently trying to make,
and explain your thoughts around it so that others can understand the situation so that they can suggest how to proceed.