these are really basic programs and really easy to be made!
Here is the code:
import java.io.*; class list{ public static void main(String[]args) throws IOException{ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); int n; System.out.println("Insert number:"); n=Integer.parseInt(stdin.readLine()); int[] prim=new int[n]; prim[0]=2; prim[1]=3; int k=1; int nr=5; int j,primj; while(k<=n-2) { j=0; primj=prim[j]; while((primj*primj<=nr) && (nr%primj!=0)) primj=prim[++j]; if(primj*primj>nr) prim[++k]=nr; nr=n+2; } for(k=0;k<n;k++) System.out.println(k+ " : "+prim[k]); } }
Here is the code`s screenshot:
Now ... this is the result, first you need to enter a number and then the list will be showed ...