Jump to content

- - - - -

[JAVA]List of primary numbers!

  • Please log in to reply
No replies to this topic

#1 _*cipcip_*

  • Guests

Posted 16 October 2007 - 11:48 AM

In this tutorial ... you are going to create in JAVA a small program that will show you a list of primary numbers ...

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:");
 int[] prim=new int[n];
 int k=1;
 int nr=5;
 int j,primj;
 while(k<=n-2) {
 while((primj*primj<=nr) && (nr%primj!=0)) primj=prim[++j];
 if(primj*primj>nr) prim[++k]=nr;
 System.out.println(k+ " : "+prim[k]);

Here is the code`s screenshot:

Posted Image

Now ... this is the result, first you need to enter a number and then the list will be showed ...

Posted Image

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users