Results 1 to 4 of 4

Thread: Whats wrong with this?

  1. #1
    NOMADMAN
    Guest

    Whats wrong with this?

    Code:
    import java.io.*;
    
    public class sortem{
       public static void main(int args[]) throws IOException {
    
    	int i=9, min=100, prevMin=0;
    
    	while (i > 0)
    	{
    	int index=9;
    		while (index >= 0)
    		{
    			if ((args[index] < min) && (args[index] > prevMin))
    				min = args[index];
    			index--;
    		}
    		System.out.println( min );
    		prevMin = min;
    		min = 100;
    		i--;
    	}
    }
    }

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I don't have Java here, so I can't test the code. But you seem to be doing a sort on 9 numbers entered through command line arguments. What problems are you facing?

    Two possible reasons could be accepting an int array instead of a String one in the psv main method, and typecasting the array elements when comparing or assigning.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    honeybee is rignt you would have to change the parameter of the main method to take a string array instead of an int array.
    Your program will compile fine with the int array in the main method but a java.lang.NoSuchMethodError will be prooduced at runtime.

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Once you change the int array into a String array i would use the parseInt() method from the Integer class for the comparison.

    Code:
    if ((Integer.parseInt(args[index]) < min && Integer.parseInt(args[index]) > prevMin);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width