Is this the best way to test a prime number?

Ok so I think I finally got my program to work. I tested It with very big 8 digit prime numbers if that means anything. here are 2 Questions about my program"
-Is this a way of finding prime numbers? (does the program fulfill its purpose?)
and Second is there a smarter way of doing it?
Here is the program:
//This program tests if a number is a prime number
import java.util.Scanner;
public class Main
public static void main ( String args [ ] )
Scanner input = new Scanner( System.in );
int number;
int bob;
System.out.print(" Enter the number you wish to test:\n");
number = input.nextInt();
if (number == 1)
System.out.print(" 1 is divisible only by 1, therefore it is not prime or composite\n");
if (number == 2)
System.out.print(" It's Prime\n ");
for ( int test = 2 ; test < number ; test++ )
bob = number % test;
if ( bob == 0)
System.out.print("It's Composite\n");
return;
System.out.println("It's Prime");
}

I got interested in this ...
//1. PrimeTester_BruteForce: found 3001134 primes <= 50000000 in 410500 milliseconds
//2. PrimeTester_SieveOfEratosthenes: found 3001134 primes <= 50000000 in 4422 milliseconds
//3. PrimeTester_SieveOfAtkin: found 3001134 primes <= 50000000 in 24843 milliseconds
... so Wkipedia's SieveOfAtkin algorithm apparently requires some serious optimization before it outruns the Greeks... see http://cr.yp.to/primegen.html for an optimized C implementation (which I can't follow).
PrimeTester_BruteForce.java//find all prime numbers upto the given maximum.
//Using the brute force method
//http://www.newton.dep.anl.gov/newton/askasci/1995/math/MATH039.HTM
//PrimeTester_BruteForce: found 3001134 primes <= 50000000 in 410500 milliseconds
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class PrimeTester_BruteForce {
     public static void main(String[] argv) throws IOException {
          long start = System.currentTimeMillis();
          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_BruteForce.txt")));
          int limit = 50000000;
          int count = 0;
nextn:     for (int n=2; n<=limit; n++) {
               int top = (int)Math.sqrt(n);
               for(int i=2; i<=top; i++) {
                    if(n%i==0) {
                         continue nextn;
               out.print(n);
               out.print(" ");
               if(++count%20==0) out.println();
          long took = System.currentTimeMillis()-start;
          out.println();
          out.println("PrimeTester_BruteForce: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
          out.close();
PrimeTester_SieveOfEratosthenes.java/******************************************************************************
//find all prime numbers upto the given maximum.
//http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
limit = 1000000;       // arbitrary search limit
// pressume all are prime
for (i=2; i<=limit; i++) is_prime[i] = true;
// eliminate multiples of each prime, starting with its square
for (n=2; n<=sqrt(limit); n++) {
   if (is_prime[n]) {
      for (i=n^2; i<=limit; i+=n) is_prime[i] = false;
// print the results
for (n=2; n=<limit; n++) {
  if (is_prime[n]) print(n);
//PrimeTester_SieveOfEratosthenes: found 164185 primes <= 1000000 in 125 milliseconds
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class PrimeTester_SieveOfEratosthenes {
     public static void main(String[] argv) throws IOException {
          long start = System.currentTimeMillis();
          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_SieveOfEratosthenes.txt")));
          int limit = 50000000;
          int n, i;
          boolean[] is_prime = new boolean[limit+1];
          // pressume all are prime
          is_prime[2] = true;
          for (i=2; i<=limit; i++) {
               is_prime[i] = true;
          // eliminate multiples of each prime, starting with its square
          for (n=1; n<=Math.sqrt(limit); n++) {
               if (is_prime[n]) {
                    for (i=n*2; i<=limit; i+=n) {
                         is_prime[i] = false;
          // print the results
          int count = 0;
          for (n=2; n<=limit; n++) {
               if (is_prime[n]) {
                    out.print(n);
                    out.print(" ");
                    if(++count%20==0) out.println();
          long took = System.currentTimeMillis()-start;
          out.println();
          out.println("PrimeTester_SieveOfEratosthenes: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
          out.close();
PrimeTester_SieveOfAtkin.java/******************************************************************************
//find all prime numbers upto the given maximum.
//http://en.wikipedia.org/wiki/Sieve_of_Atkin
limit = 1000000; // Arbitrary search limit
array is_prime[5:limit] initial false; // Sieve array.
biginteger x,y,n,k; // Must be able to hold 5*limit: 4x^2 + y^2!
// put in candidate primes: integers which have an odd number of representations
// by certain quadratic forms.
for x:=1:sqrt(limit) do
for y:=1:sqrt(limit) do
   n:=4x^2 + y^2; if n<=limit and n%12 = 1 or 5 then is_prime[n]:=not is_prime[n];
   n:=3x^2 + y^2; if n<=limit and n%12 = 7 then is_prime[n]:=not is_prime[n];
   n:=3x^2 - y^2; if n<=limit and x>y and n%12 = 11 then is_prime[n]:=not is_prime[n];
next y;
next x;
// eliminate composites by sieving
// if n is prime, omit all multiples of its square; this is sufficient because
// composites which managed to get on the list cannot be square-free
for n:=5:sqrt(limit) do
  if is_prime[n] then for k:=n^2:limit:n^2 do is_prime[k]:=false; next k;
next n;
// Present the results.
print 2, 3; for n:= 5:limit do if is_prime[n] then print n; next n;
//PrimeTester_SieveOfAtkin: found 441 primes <= 1000000 in 203 milliseconds
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class PrimeTester_SieveOfAtkin {
     public static void main(String[] argv) throws IOException {
          long start = System.currentTimeMillis();
          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_SieveOfAtkin.txt")));
          int limit = 50000000;
          int sqrt = (int)Math.sqrt(limit);
          boolean[] is_prime = new boolean[limit+1]; // Sieve array.
          int x, y, n, k; // Must be able to hold 5*limit: 4x^2 + y^2!
          // put in candidate primes: integers which have an odd number of representations by certain quadratic forms.
          for (x=1; x<=sqrt; x++) {
               for (y=1; y<=sqrt; y++) {
                    //n=(4*(x^2)) + y^2; if (n<=limit && n%12 in(1,5)) is_prime[n] = !is_prime[n];
                    int xSq = (int)Math.pow(x,2);
                    int ySq = (int)Math.pow(y,2);
                    n = 4*xSq + ySq;
                    if (n<=limit && (n%12==1||n%12==5)) {
                         is_prime[n]= !is_prime[n];
                         //debug("A: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
                    //n=((3*(x^2)) + y^2; if (n<=limit && n%12==7) is_prime[n] = !is_prime[n];
                    n = 3*xSq + ySq;
                    if (n<=limit && n%12==7) {
                         is_prime[n]= !is_prime[n];
                         //debug("B: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
                         //debug("   if (n<=limit:"+limit+" && n%12:"+(n%12)+"==7");
                         //debug("   (3*(x^2)):"+xSq+" + (y^2):"+ySq);
                    //n=((3*(x^2)) - y^2; if (n<=limit && x>y && n%12==11) is_prime[n]= !is_prime[n];
                    n = 3*xSq - ySq;
                    if (n<=limit && x>y && (n%12==11)) {
                         is_prime[n]= !is_prime[n];
                         //debug("C: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
               }//next y
          }//next x
          // eliminate composites by sieving
          // if n is prime, omit all multiples of its square; this is sufficient because
          // composites which managed to get on the list cannot be square-free
          // for (n:=5:sqrt(limit)) {
          //   if (is_prime[n]) for (k:=n^2:limit:n^2) is_prime[k]:=false;
          for (n=5; n<=sqrt; n++) {
               if (is_prime[n]) {
                    int nSq = (int)Math.pow(n,2);
                    for(k=nSq; k<=limit; k+=nSq) {
                         is_prime[k]=false;
                         //debug("D: n="+n+" is_prime["+k+"]="+is_prime[k]);
          // Present the results.
          int count = 2;
          out.print("2 3 ");
          for(n=5; n<=limit; n++) {
               if(is_prime[n]) {
                    out.format("%d ", n);
                    if(++count%20==0) out.println();
          long took = System.currentTimeMillis()-start;
          out.println();
          out.println("PrimeTester_SieveOfAtkin: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
          out.close();
     //private static void debug(String msg) {
     //     System.out.println(msg);
}

Similar Messages

  • Cfqueryparam numeric help - is this the best way

    I have an update in one of my programs and I'm using the
    cfqueryparam. It works fine if the value is not entered since the
    type is cf_sql_varchar. If the value is cf_sql_integer/cf_sql_float
    and the field is required, it again works fine. Now if the field is
    cf_sql_integer and not required, it will throw an error if no value
    is passed to it. I tried using the NULL parameter, but that will
    put NULL in the field every time. I finally ended up using a cfif
    statement to check. Is this the best way? Am I missing something?
    How do others handle this?

    Your's is as good a way as any. But since you asked, my
    approach is usually like this:
    Step 1, build a string variable called sql. Perform all your
    if/else and other logic at this step.
    Step 2
    <cfquery>
    #PreserveSingleQuotes(sql)#
    </cfquery>
    My method makes it almost impossible to use cfqueryparam
    because of all the quotes. However, I find it easier to develop,
    read, and maintain code when you have as much if/else, loop, etc
    processing in the same block of code.
    You might be able to do both. Something like
    Step 1 - use if/else logic to set a variable (call it null)
    to either yes or no.
    Step 2
    cfqueryparam null="#null#">
    I've never actually tried. Most of my work is with a db that
    does not support cfqueryparam so using it is not a high priority
    item for me.

  • BC4J datatags: is this the best way to do this?

    In my BC4J JSP application, in the DataTableComponent.jsp, I want to check
    if a property exists on the view object. This is the best way I could come
    up with:
    String PropertyValue =
    (String)dsBrowse.getApplicationModule()
    .findViewObject(dsBrowse.getViewObjectName())
    .getProperty("PropertyName");
    Is this the proper way to get at a view property? Seems like it should be more straightforward.
    Also, does an instance of the ViewImpl class get automatically created when the DataSource tag is used or do you have to specifically instantiate it if you want to use a client method on the view?
    Thanks,
    Steve

    You can do:
       String propVal = dsBrowse.getRowSet().getViewObject().getProperty("PropName");You do not have to instantiate any classes on your own to accomplish this.

  • What is the best way to test connection keys?

    I've created multiple connection key for various rolse on a
    new site. When I select the key it asks if I want to replace the
    existing connection, which I really don't want to do.
    What is the best way to handle this so the administrative
    connection is not affected?

    Also create a connection key for you administrator role, so
    you can swiftly switch back.

  • Is this the best way to redirect using servlet?

    I making a servlet application where the user sends some FORM value to a servlet. I want the servlet to redirect to the answer page after processing the page. Do you think the following code is the correct way of doing?
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            String dnaText = request.getParameter("dnaText");
            /*Getting the tranlated output from dnaToRna method*/
            String finalVal = null;
            String link="http://www.mail.yahoo.com";
            try{
                 finalVal = String.valueOf(dnaToRna(dnaText));
                 response.sendRedirect(link);
                }catch(Exception ex){}
        }

    Many thanks for replying.
    My output file have lots of html code and I dont want to make my servlet heavy with unnecessary code. So I have decided to use another page result.jsp as output file. In result.jsp I intend to call these objects which is storing the value here to display the result.
    As I am new to jsp. I am still in the processing of thinking the best way to handle errors. I have created a method which takes in int values and returns corresponding String values. Like this
    public class DnaToRna extends HttpServlet {
       String error=" * NULL *";
    private String printError(int i) {
            if(i==1){
                error = "There is an error in String to char array";
            }else if (i==2){
                error = "There is an error in your DNA sequence";
            return error;
        }Since error is declared as a class object, if there is no error then I think it should rerun the String NULL. Which can be used to tell people if there is no error. On the contrary if there is really an error, I can use this to tell what is exactly causing the error.
    Although I am new to web programing. I think this would be nice.
    Here is the other method
    public String dnaToRna (String dnaText) throws Exception{
                /*Trim()*/
                dnaText = dnaText.trim();
                /*Codes for Dna to Rna translation*/
                if(Pattern.matches(".*[^atgc]+.*",dnaText))
                return printError(2);
                return dnaText.replaceAll("t","u");
                }

  • Is This The Best Way To Put iMovie Effects On An FCE Clip?

    I have often suggested to other people that they should export clips from FCE to iMovie in order to make use of certain iMovie effects that FCE can't do.
    As with most things there are several different ways of "transporting" the clips.
    Bearing in mind that we want the quickest/lossless method possible, is this the best?
    1. In the FCE Timeline double-click the clip.
    2. Select File>Export>QuickTime Movie and click "Save".
    3.Open a new iMovie Project, import the newly made QuickTime Movie clip and add the necessary effect.
    4. Back in FCE, Import the QuickTime Movie from the iMovie Project.
    Is this in fact the best way or do you know of a better/quicker one?
    Ian.

    Thanks for the confirmation, Tom.
    By "clip" I was actually meaning a few seconds of video I had chopped up on the timeline.
    What caught me out initially was when I simply highlighted the 10 second "clip" and selected QuickTime Movie.
    The estimated time for conversion was around 10 minutes! It was actually making a QT Movie of the complete Sequence, not just the selected "clip". I soon realised that the "clip" needed double-clicking to ensure that only the required 10 seconds were converted.
    Ian.

  • Adding buttons to multiple frames -- is this the best way to do this?

    In CS5, I want to create a series of buttons that when clicked will linked to other frames in the same timeline. So one button will link to frame 5, one will link to frame 10, one will link to 15, etc. All the buttons will appear across the top of the stage on a layer, and I want them to appear on all of the frames so the user can click back-and-forth to the different frames/screens.
    1. Is the best way to do this to just add the buttons to frame 1 and add a keyframe to the last frame in the timeline, frame 15, so they are copied to all the frames in between?
    2. Are there any issues with doing it this way?
    Thanks!!!

    Just have the one keyframe in frame 1 and extend it to frame 15.  You do not need/want another keyframe at frame 15.

  • Is this the best way to measure the speed of an input stream?

    Hi guys,
    I have written the following method to read the source of a web page. I have added the functionality to calculate the speed.
    public StringBuffer read(String url)
            int lc = 0;
            long lastSpeed = System.currentTimeMillis();
            //string buffer for reading in the characters
            StringBuffer buffer = new StringBuffer();
            try
                //try to set URL
                URL URL = new URL(url);
                //create input streams
                InputStream content = (InputStream) URL.getContent();
                BufferedReader in = new BufferedReader(new InputStreamReader(content));
                //in line
                String line;
                //while still reading in
                while ((line = in.readLine()) != null)
                    lc++;
                    if ((lc % _Sample_Rate) == 0)
                        this.setSpeed(System.currentTimeMillis() - lastSpeed);
                        lastSpeed = System.currentTimeMillis();
                    //add character to string buffer
                    buffer.append(line);
            //catch errors
            catch (MalformedURLException e)
                System.out.println("Invalid URL - " + e);
            catch (IOException e)
                System.out.println("Invalid URL - " + e);
            //return source
            return buffer;
        }Is it faster to read bytes rather than characters?
    This method is a very important part of my project and must be as quick as possible.
    Any ideas on how I can make it quicker? Is my approach to calculating the speed the best way to it?
    Any help/suggestions would be great.
    thanks
    alex

    sigh
    reading bytes might be slightly faster than reading chars, since you don't have to do the conversion and you don't have to make String objects. Certainly, you don't want to use readLine. If you're using a reader, use read(buf, length, offset)
    My suggestion:
    Get your inputstream, put a bufferedInputStream over it, and use tje loadAll method from my IOUtils class.
    IOUtils is given freely, but please do not change its package or submit this as your own work.
    ====
    package tjacobs;
    import java.awt.Component;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import javax.swing.JOptionPane;
    public class IOUtils {
         public static final int DEFAULT_BUFFER_SIZE = (int) Math.pow(2, 20); //1 MByte
         public static final int DEFAULT_WAIT_TIME = 30 * 1000; // 30 Seconds
         public static final int NO_TIMEOUT = -1;
         public static final boolean ALWAYS_BACKUP = false;
         public static String loadTextFile(File f) throws IOException {
              BufferedReader br = new BufferedReader(new FileReader(f));
              char data[] = new char[(int)f.length()];
              int got = 0;
              do {
                   got += br.read(data, got, data.length - got);
              while (got < data.length);
              return new String(data);
         public static class TIMEOUT implements Runnable {
              private long mWaitTime;
              private boolean mRunning = true;
              private Thread mMyThread;
              public TIMEOUT() {
                   this(DEFAULT_WAIT_TIME);
              public TIMEOUT(int timeToWait) {
                   mWaitTime = timeToWait;
              public void stop() {
                   mRunning = false;
                   mMyThread.interrupt();
              public void run () {
                   mMyThread = Thread.currentThread();
                   while (true) {
                        try {
                             Thread.sleep(mWaitTime);
                        catch (InterruptedException ex) {
                             if (!mRunning) {
                                  return;
         public static InfoFetcher loadData(InputStream in) {
              byte buf[] = new byte[DEFAULT_BUFFER_SIZE]; // 1 MByte
              return loadData(in, buf);
         public static InfoFetcher loadData(InputStream in, byte buf[]) {
              return loadData(in, buf, DEFAULT_WAIT_TIME);
         public static InfoFetcher loadData(InputStream in, byte buf[], int waitTime) {
              return new InfoFetcher(in, buf, waitTime);
         public static String loadAllString(InputStream in) {
              InfoFetcher fetcher = loadData(in);
              fetcher.run();
              return new String(fetcher.buf, 0, fetcher.got);
         public static byte[] loadAll(InputStream in) {
              InfoFetcher fetcher = loadData(in);
              fetcher.run();
              byte bytes[] = new byte[fetcher.got];
              for (int i = 0; i < fetcher.got; i++) {
                   bytes[i] = fetcher.buf;
              return bytes;
         public static class PartialReadException extends RuntimeException {
              public PartialReadException(int got, int total) {
                   super("Got " + got + " of " + total + " bytes");
         public static class InfoFetcher implements Runnable {
              public byte[] buf;
              public InputStream in;
              public int waitTime;
              private ArrayList mListeners;
              public int got = 0;
              protected boolean mClearBufferFlag = false;
              public InfoFetcher(InputStream in, byte[] buf, int waitTime) {
                   this.buf = buf;
                   this.in = in;
                   this.waitTime = waitTime;
              public void addInputStreamListener(InputStreamListener fll) {
                   if (mListeners == null) {
                        mListeners = new ArrayList(2);
                   if (!mListeners.contains(fll)) {
                        mListeners.add(fll);
              public void removeInputStreamListener(InputStreamListener fll) {
                   if (mListeners == null) {
                        return;
                   mListeners.remove(fll);
              public byte[] readCompletely() {
                   run();
                   return buf;
              public int got() {
                   return got;
              public void run() {
                   if (waitTime > 0) {
                        TIMEOUT to = new TIMEOUT(waitTime);
                        Thread t = new Thread(to);
                        t.start();
                   int b;
                   try {
                        while ((b = in.read()) != -1) {
                             if (got + 1 > buf.length) {
                                  buf = expandBuf(buf);
                             buf[got++] = (byte) b;
                             int available = in.available();
                             if (got + available > buf.length) {
                                  buf = expandBuf(buf);
                             got += in.read(buf, got, available);
                             signalListeners(false);
                             if (mClearBufferFlag) {
                                  mClearBufferFlag = false;
                                  got = 0;
                   } catch (IOException iox) {
                        throw new PartialReadException(got, buf.length);
                   } finally {
                        buf = trimBuf(buf, got);
                        signalListeners(true);
              private void setClearBufferFlag(boolean status) {
                   mClearBufferFlag = status;
              public void clearBuffer() {
                   setClearBufferFlag(true);
              private void signalListeners(boolean over) {
                   if (mListeners != null) {
                        Iterator i = mListeners.iterator();
                        InputStreamEvent ev = new InputStreamEvent(got, buf);
                        //System.out.println("got: " + got + " buf = " + new String(buf, 0, 20));
                        while (i.hasNext()) {
                             InputStreamListener fll = (InputStreamListener) i.next();
                             if (over) {
                                  fll.gotAll(ev);
                             } else {
                                  fll.gotMore(ev);
         public static interface InputStreamListener {
              public void gotMore(InputStreamEvent ev);
              public void gotAll(InputStreamEvent ev);
         public static class InputStreamEvent {
              public int totalBytesRetrieved;
              public byte buffer[];
              public InputStreamEvent (int bytes, byte buf[]) {
                   totalBytesRetrieved = bytes;
                   buffer = buf;
              public int getBytesRetrieved() {
                   return totalBytesRetrieved;
              public byte[] getBytes() {
                   return buffer;
         public static void copyBufs(byte src[], byte target[]) {
              int length = Math.min(src.length, target.length);
              for (int i = 0; i < length; i++) {
                   target[i] = src[i];
         public static byte[] expandBuf(byte array[]) {
              int length = array.length;
              byte newbuf[] = new byte[length *2];
              copyBufs(array, newbuf);
              return newbuf;
         public static byte[] trimBuf(byte[] array, int size) {
              byte[] newbuf = new byte[size];
              for (int i = 0; i < size; i++) {
                   newbuf[i] = array[i];
              return newbuf;

  • MouseOver is this the best way?

    I'm trying to create mouse over (tool tip) for everything in
    my simulated control panel my question is, is mouseOver event
    handler the best way to have the program display a small amout of
    text over the mouse pointer. seems to me this is done all the time
    and there should be a better way.
    thank you in advance for your help

    kglad i agree on the Array way i have many buttons, lights,
    vents,......... that i want tool tips for so i will do the Array.
    another dumb question what is bubbling i did not see a differance
    when i tried MOUSE or ROLL.
    i thought
    Knobtip.x = this.mouseX;
    Knobtip.y = this.mouseY;
    would make the tip follow the mouse pointer.
    thanks again guys i'm taking a 5 day class in 2 weeks so i
    will not (hopefully) ask so many stupid questions

  • What is the best way to show/hide n number of columns ?

    Hi,
    I have a dynamic report that I have show/hide columns working using the below code. But when there are 500 or more rows it takes about a minute or more just waiting to see the columns toggle.
    What is the best way to do this?
    // Existing Javascript
    [script language="JavaScript" type="text/javascript"]
    var maxcnt= mymonths.length;
    function hideMaxEarn(){
    for(var j=0;j[maxcnt;j++){
    hideColumn('MON'+mymonths[j],'MAXCOL'+mymonths[j]);
    hideColumn('MON'+mymonths[j],'EARNCOL'+mymonths[j]);
    hideColumn('MON13','MAXCOL13');
    hideColumn('MON13','EARNCOL13');
    function showMaxEarn(){
    for(var j=0;j[maxcnt;j++){
    showColumn('MON'+mymonths[j],'MAXCOL'+mymonths[j]);
    showColumn('MON'+mymonths[j],'EARNCOL'+mymonths[j]);
    showColumn('MON13','MAXCOL13');
    showColumn('MON13','EARNCOL13');
    function getCellIndex(pRow,pCell){ 
    for(var i=0, n=pRow.cells.length;i[n;i++){ 
        if(pRow.cells[i] == pCell) return i;
    function hideColumn(pMon,pCol){
    var l_Cell = $x(pCol);
    var l_Table = html_CascadeUpTill(l_Cell,'TABLE');
    var l_Rows = l_Table.rows;
    l_CellI = getCellIndex(l_Cell.parentNode,l_Cell);
    for (var i=0, n=l_Rows.length;i[n;i++){
        if(i != 0) {
           html_HideElement(l_Rows[i].cells[l_CellI]);
    } else {
    $x(pMon).colSpan = $x(pMon).colSpan - 1;
    function showColumn(pMon,pCol){
    var l_Cell = $x(pCol);
    var l_Table = html_CascadeUpTill(l_Cell,'TABLE');
    var l_Rows = l_Table.rows;
    l_CellI = getCellIndex(l_Cell.parentNode,l_Cell);
    for (var i=0, n=l_Rows.length;i[n;i++){
        if(i != 0) {
           html_ShowElement(l_Rows[i].cells[l_CellI]);
    } else {
    $x(pMon).colSpan = 3;
    return;
    [script]

    Hi Andy,
    Yes, I replaced the code calling the same things in a loop to one loop getting the Table reference once and I build an array of column numbers at the time the report is built so I don't have to get the column number each time....
    it is a couple of seconds faster in about a 30 second response time. It will have to do it for now, no more time unless you see something in this new code...
    Thank you! Bill
    // dynamically built code
    col_nbr_array = new Array();
    col_nbr_array[0] = "1";
    col_nbr_array[1] = "2";
    col_nbr_array[2] = "4";
    col_nbr_array[3] = "5";
    col_nbr_array[4] = "7";
    col_nbr_array[5] = "8";
    col_nbr_array[6] = "10";
    col_nbr_array[7] = "11";
    col_nbr_array[8] = "13";
    col_nbr_array[9] = "14";
    col_nbr_array[10] = "16";
    col_nbr_array[11] = "17";
    col_nbr_array[12] = "19";
    col_nbr_array[13] = "20";
    col_nbr_array[14] = "22";
    col_nbr_array[15] = "23";
    col_nbr_array[16] = "25";
    col_nbr_array[17] = "26";
    col_nbr_array[18] = "28";
    col_nbr_array[19] = "29";
    col_nbr_array[20] = "31";
    col_nbr_array[21] = "32";
    col_nbr_array[22] = "34";
    col_nbr_array[23] = "35";
    col_nbr_array[24] = "37";
    col_nbr_array[25] = "38";
    col_nbr_array[26] = "40";
    col_nbr_array[27] = "41";
    // Static code
    function show_hide_column(do_show) {
    // Set Style, Show/Hide
    var stl;
    var csp;
    if (do_show){
    stl = 'block'
    csp = 3;
    }else{
    stl = 'none';     
    csp = 1;     
    // get rows object
    var l_Rows = document.getElementById('DT_RANGE').rows;
    var totCellNbr1=parseFloat(col_nbr_array[maxcnt-1])+2;
    var totCellNbr2=totCellNbr1 +1;
    var n=l_Rows.length;
    for (var i=0; i[n;i++){
        if(i != 0) { // if not the main header which spans 3 cols when expanded
          // Go through and show/hide each cell
          for(var j=0;j[maxcnt;j++){
              l_Rows[i].cells[col_nbr_array[j]].style.display = stl;
    // Totals
    l_Rows.cells[totCellNbr1].style.display=stl;
    l_Rows[i].cells[totCellNbr2].style.display=stl;
    } else { // row 1 that has Month spelled out - colspan of 3, others has max,earned and score columns for each month.
    var maxhdr = maxcnt/2;
    for(var k=1;k[=maxhdr;k=k+1){
    //alert('Header['+k+']');
    l_Rows[i].cells[k].colSpan=csp;
    // Total column
    //alert('TotHeader['+(maxhdr+1)+']');
    l_Rows[i].cells[maxhdr+1].colSpan=csp;
    [script]

  • Which is the best way for posting a large number of records?

    I have around 12000 register to commit to dababase.
    Which is the best way for doing it?
    What depends on ?
    Nowadays I can't commit such a large number of register..The dabatase seems hanged!!!
    Thanks in advance

    Xavi wrote:
    Nowadays I can't commit such a large number of registerIt should be possible to insert tens of thousands of rows in a few seconds using an insert statement even with a complex query such as the all_objects view, and commit at the end.
    SQL> create table t as select * from all_objects where 0 = 1;
    Table created.
    Elapsed: 00:00:00.03
    SQL> insert into t select * from all_objects;
    32151 rows created.
    Elapsed: 00:00:09.01
    SQL> commit;
    Commit complete.
    Elapsed: 00:00:00.00
    I meant RECORDS instead of REGISTERS.Maybe that is where you are going wrong, records are for putting on turntables.

  • Is this the best way to Triple Boot?

    Hi all, I have a had a pickle of a time setting up Leopard...with my triple boot setup.
    I am curious if I went about it "properly"or if there is a better way.
    Use instructions at your own peril if you wish. I am not responsible for errors or any problems you may have by using my instructions. This is my individual experience. *I am happy if this works for someone* struggling to set up a triple boot, but am posting this more so to see if there are any improvements to be made, or mistakes that need correcting to this method...
    I had an Intel MBP (SR) with 3 partitions. Tiger, Vista and Ubuntu but when trying to install Leopard it said it would not install and I would have to change my drive to guid partition scheme.
    So, through trial and error this is the only way I could get it to work.Keep in mind I started from scratch with vista and ubuntu, but did make a backup of my tiger drive.
    1. BACK UP
    2. Wipe everything and repartition internal disk to guid partition map and 1 partition. Install Leopard.
    3. Use either disk utility or carbon copy cloner(my purchased copy of SuperDuper is still not able to do what CCC, a free program can do,apparently because they are trying to figure out time machine and are holding up a leopard compat. version, uuughh, but thats a different post...) to clone Leopard to external drive that is set up as GUID partition scheme.Make sure you are able to boot this external.
    4. Wipe internal, repartition to 3 partitions using disk utility and MBR partition scheme in this order from top to bottom(in disk utility partition gui);
      a. Leopard partition: OSX extended journaled
      b. Vista partition: I think there is only one option: maybe Fat? Just make sure you select "windows" format (The vista installer will need to reformat this during install anyway)
      c. Ubuntu partition: "Free Space"
    5. Then to install leopard, (which apparently won't install on a drive set up as MBR partition scheme, but that is what we formatted the internal drive as anyway) clone the external copy of leopard to the internal OSX partition we just made.
    6. Then install vista by booting from install cd. During install you may have to reformat the Windows partition using the windows installer, but it should install fine after that.
    7. Then Install ubuntu using live cd/dvd to the internal free space partition, splitting/ formatting the last partition using the ubuntu install/partition tool on the "manual"partition mode(make sure you are using the correct free space partition. I confirmed this by looking at the sizes of the partitions that showed up): "free space" into root and swap partitions if you want. I used ext2 for root
         *Side note:*If you have the same MBP as me you may have to change some setting when booting the live cd: Once the cd loads and you get to the preliminary menu window, press F6 to edit. A command will show up on the screen: You have to erase the last two words starting at "quiet" till end. Then write "allgenericide" in their space, keeping all of the command before quiet.  then press enter. It should then load to the ubuntu desktop where you can click on the install icon.(this took me a long time to figure out. I have also have to do this everytime I want boot into ubuntu, which stinks. Anyone know how to resolve this? (Linux masters?)
    8. boot into osx and install rEFIt
    Issues:
    1. My Leopard partition is not showing up in OSX's startup disk pane in sys pref. but it is booting/ showing up as if it was, if having trouble, try holding option key during startup.
    2. I have also had a few issues with rEFIt not starting up as default menu, but when holding option key at startup it will show up. Then gives me the option of OSX, Vista or Ubuntu once selected.
    3. And the command thing with ubuntu at every startup I mentioned earlier.Is there a way to write allgenericide as a default or any other way to fix this?
    If anyone has a better way of accomplishing this please let me know. I got to this point through a lot of trial and error and I'm not sure if there is a more stable/better way for a triple boot setup...
    I would like for the Leopard partition to show up as the osx startup disk in the pref pane, but regardless it is still working.
    Correct me if I'm wrong, but it seems boot camp makes the drive into an MBR partition scheme anyway, so I'm curious what others who were already running dual or triple boot, boot camp systems had to do when upgrading their boot camp setups from tiger to leopard. Did it not allow you to install to the MBR partition scheme made by boot camp? Did you have to start from scratch as well?
    Thank you in advance for your patience and support.  

    http://wiki.onmac.net/index.php/TripleBoot_viaBootCampI would install Vista before installing Leopard.
    That has worked better for me anyway.
    And that may make Leopard the default.
    In Vista, AppleControl is under /Windows/SysWOW64 if you ever need to get to it (there is also AppleOSSMgr and AppleTimeSrvc )
    http://wiki.onmac.net/index.php/TripleBoot_viaBootCamp

  • What is the best way of testing a custom web service

    We have a custom developed service (a jar sitting in the xmlpserver/WEB-INF/lib folder) on the BI Publisher server. This service uses the BookBinder class to concatenate some documents.
    We call this service through Axis (PublicReportService_v11) from a 3rd party application, passing in all the details to complete the call.
    I inherited this peace of code and now I need to build some kind of automated test to make sure the service is properly tested. We are using version 10.1.3.4.1.
    I started writing a Java application to send requests but I'm not too sure how to call our custom service. The code looks something like this:
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import javax.xml.namespace.QName;
    public class Test_Web_Service
    public static void main(String [] args) throws Exception {
    try {
    String endpoint = "http://bipserver:port/xmlpserver/services/PublicReportService_v11";
    Service service = new Service();
    Call call= (Call) service.createCall();
    call.setProperty( call.USERNAME_PROPERTY, "bob" );
    call.setProperty( call.SPASSWORD_PROPERTY, "pw");
    call.setTargetEndpointAddress( new java.net.URL(endpoint) );
    call.setOperationName(new QName("http://bipserver:port/xmlpserver/services/PublicReportService_v11","myCustomService"));
    String ret = (String) call.invoke( new Object[] {""} );
    System.out.println("Sent '20', got '" + ret + "'");
    } catch (Exception e) {
    System.err.println(e.toString());
    I'm getting a NullPointerException.
    Edited by: user612544 on 28-Feb-2013 07:13

    I'd recommend a tool like SoapUI (http://www.soapui.org/) - the basic version is free and probably all you'll need.
    Barry Goodsell.
    Please mark as answered if helpful

  • What is the best way to test for collisions between objects?

    I am in the process of developing my first game, my first decent game that is. I understand how to develop the background and tileset for the game, but have yet to figure out an effective way of testing for collisions. As in you try to move the character into a wall, or another object on the level.
    If I divide the level into tiles, it won't be to hard, but I am thinking I want to have the hero be able to move all over the place, not just from square to square.
    Any suggestions or ideas will be greatly appreciated

    If I divide the level into tiles, it won't be to hard,
    but I am thinking I want to have the hero be able to
    move all over the place, not just from square to
    square.Err...
    So if the hero is not on a square, the hero is not on a tile and consequently is not on a visible aspect of the game world?
    I suspect that you wanted the hero to be able to move in any direction, not just the standard cardinal directions.
    If you're using tiles to represent the game world, then the solution is simple - check to see if there's anything "solid" already on the target tile. If there is, abort the move and report it as a collision. If there isn't, permit the move.
    It's only when you have a tile-less world that you actually have to determine if the leading edge of your hero crosses the boundary of an item (or border) that he shouldn't be allowed to cross. Doing so is complicated enough that I would simply suggest that you search the forum for third party collision detection packages that you can borrow.

  • Is this the best way to write this in AS3

    I have converted my old AS2 to As3. It now appears to work the same as before but being new to AS3 I have a few questions.
    In this example I click on a button which takes me to a keyframe that plays a MC. There is another btn that takes me back to the original page.
    In AS2 it is written like this.
    // Go to keyFrame btn
    on (release) {
    //Movieclip GotoAndStop Behavior
    this.gotoAndStop("Jpn_Scul_mc");
    //End Behavior
    // Play Movie
    on (release) {
    //Movieclip GotoAndStop Behavior
    this.gotoAndStop("Jpn_Movie");
    //End Behavior
    //load Movie Behavior
    if(this.mcContentHolder == Number(this.mcContentHolder)){
    loadMovieNum("PL_Japan_Scul.swf",this.mcContentHolder);
    } else {
    this.mcContentHolder.loadMovie("PL_Japan_Scul.swf");
    //End Behavior
    // Return key
    on (release) {
    //Movieclip GotoAndStop Behavior
    this.gotoAndStop("Jpn_Intro");
    //End Behavior
    In AS3 it is written like this.
    // Play Movie
    var myrequest_Jpn:URLRequest=new URLRequest("PL_Japan_Scul.swf");
    var myloader_Jpn:Loader=new Loader();
    myloader_Jpn.load(myrequest_Jpn);
    function movieLoaded_Jpn(myevent_Jpn:Event):void {
    stage.addChild(myloader_Jpn);
    var mycontent:MovieClip=myevent_Jpn.target.content;
    mycontent.x=20;
    mycontent.y=20;
    //unload method - Return to keyframe
    function Rtn_Jpn_Intro_(e:Event):void {
    gotoAndStop("Japan_Intro");
    Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
    function removeMovie_Jpn(myevent_Jpn:MouseEvent):void {
    myloader_Jpn.unload();
    myloader_Jpn.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_Jpn);
    Rtn_Jpn_Intro_btn.addEventListener("click",Rtn_Jpn_Intro_);
    // Go to keyFrame btn
    function Scul_Play(e:Event):void {
    gotoAndStop("Jpn_Scul_mc");
    Jpn_Scul_btn.addEventListener("click",Scul_Play);
    1. Is there a better, more efficient way to achieve this in AS3?
    2. I have used an //unload method in the AS3 script which does remove the MC from the scene but I notice in the output tab my variable code is still being counted for the last MC played.
    Is this normal?

    Hi Andrei, I have started a new project and taken your advice to construct it with a different architecture with all the code in one place.
    I have two questions regarding your last code update.
    var myrequest_Jpn:URLRequest;
    var myloader_Jpn:Loader;
    Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
    Jpn_Scul_btn.addEventListener(MouseEvent.CLICK, Scul_Play);
    function Scul_Play(e:MouseEvent):void {
         myrequest_Jpn = new URLRequest("PL_Japan_Scul.swf");
         myloader_Jpn = new Loader();
         myloader_Jpn.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_Jpn);
         myloader_Jpn.load(myrequest_Jpn);
    function movieLoaded_Jpn(e:Event):void {
         // remove listener
         myevent_Jpn.target.removeEventListener(Event.COMPLETE, movieLoaded_Jpn);
         this.addChild(myloader_Jpn);
         myloader_Jpn.x = 20;
         myloader_Jpn.y = 20;
         // remove objects that are in "Japan_Intro" frame
    function removeMovie_Jpn(e:MouseEvent):void {
         // add back objects that are in "Japan_Intro" frame
         // remove from display list
         this.removeChild(myloader_Jpn);
         myloader_Jpn.unload();
         myloader_Jpn = null;
         // this moved from Rtn_Jpn_Intro_ function
         //gotoAndStop("Japan_Intro");
    Its all works great except for the line to remove event..
    1.
    myevent_Jpn.target.removeEventListener(Event.COMPLETE, movieLoaded_Jpn);
    I get an error:   1120: Access of undefined property myevent_Jpn.
    Removing this statement allows the code to work but that is not a solution.
    2.
    Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
    I would like this button to remove more than one movie. Is this possible.
    Thanks for the help todate.

Maybe you are looking for

  • How to connect my wifi printer to my MacBook Pro

    Hello - Could you please advise re: how to connect my HP Deskjet 3050 to my MacBook Pro?  I gather I have to connect the printer to my Wifi network first, but the instructions aren't clear for a Mac. Please help.  Thank you -

  • Report : Schedule Lines

    dear All , I need a report for the schedule lines for custoemer which we mention in Sales order. Pl guide for the same . Regards

  • Acrobat Pro Trial wiped out my licensed version of Acrobat Standard

    I recently wanted to convert a PDF back to Microsoft Word because I could not find my original Word file. I thought Acrobat Standard would do it, but apparently not. Online research told me that I could download an Acrobat Pro Trial license, which ca

  • Table for Cost Distribution

    Hi, I am creating a PO and the item amount is distributed to different cost centers by Qty, Value, %. I am looking for 1) Table information where the ditribution is stored. 2) Can I use the distribution of Limit Orders?

  • Windows 7 - Oracle10g installation

    Hi, Please let me know is there oracle10g binary available for windows 7 64bit machine? Thanks KSG