I got a task to write a java program which can solve some mathematical actions. Every action has to be in separate methods. My problem is with a method which should sort prime numbers between 0 and a given number. The code works without the method but I have to implement into a method anyway and that's the problem. I tried many different ways with array etc but nothing works. I guess it's a very simple and easy task for many of you but I'm totally beginner so I would like to ask for you help. Thanks!
public class prim4 {
public static void main (String[] args) {
int prim=50;
int j;
boolean control;
for (j=1; j<=prim; j++)
{
control=primtal(j);
if (control=false)
{
break;
}
if (control=true)
{
System.out.println(j + " ");
}
}
}
public static boolean primtal (int j)
{
int i;
boolean result;
for (i=2; i < j ;i++ ){
int temp = j%i;
if (temp==0)
{
result=false;
}
}
if(i == j){
{
result=true;
}
return result;
}
}
}
