Results 1 to 6 of 6
  1. #1
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default println doesn't print from inside for loop, et.al.

    I have a dual boot Windows Vista / Ubuntu 10.8 system on which I am learning java using eclipse. Slowly working my way through the Sun tutorials and am working on the first exercise of the container class which asks us to read the command line arguments and print them in a random order.

    I have code that works within the eclipse ide on both linux and windows, but it doesn't print any println statements that are called within a for loop if I run the application from a command line.
    **********************
    package rdt_RandArgs;


    import java.util.*;

    public class RandArgs {


    public static void main(String[] args) {
    Random rndInt = new Random(9);
    int foo, ndx;
    String tmp = "";
    int iLstLen = 0;

    package rdt_RandArgs;


    import java.util.*;

    public class RandArgs {


    public static void main(String[] args) {
    Random rndInt = new Random(9);
    int foo, ndx;
    String tmp = "";
    int iLstLen = 0;

    List lstArgs = new LinkedList();
    iLstLen = args.length;

    for( ndx = 0; ndx < iLstLen; ndx++){
    lstArgs.add((String) args[ndx]);

    System.out.print(lstArgs.get(ndx) + " ");
    } //for
    System.out.println("");
    for( ndx = 0; ndx < iLstLen; ndx++){
    foo = rndInt.nextInt(lstArgs.size());
    System.out.print(lstArgs.get(foo) + " ");
    lstArgs.remove(foo);
    } //for
    System.out.println("Hello World");
    } //class
    }

    This has me totally buffaloed.

    Problem no 2:
    List lstArgs = new LinkedList();
    My first go around used List<String> lstArgs = new LinkedList<String>();
    This is modeled after code in the tutorial, but I started getting errors that I can only use this code if my project or workspace is configured to use jre 1.5.
    What's happening? Is this going to break a lot of code?

    If I compile the present code from the command line, I get a warning to use Xlint which gives me this err ms.:

    RandArgs.java:19: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
    lstArgs.add(args[ndx]);
    Suspect I need some sort of cast, but what do I need to do to get rid of error.
    Dick T.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    That's a warning and not an error, and should not effect the running of your code. I wonder if it's a problem with using a console from command line.

  3. #3
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default chat

    Err messages make me uncomfortable, and I don't have the experience to dismiss them like I might in C where I would probably know what I could and couldn't do.

    I tried the answer sun supplied and it did the same thing. Wouldn't print from command line.

  4. #4
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    Boy, what a dolt I am. The program sorts the command arguments. If I don't provide command arguments, I get no output.

    Would still like to get rid of the warning, if possible.

  5. #5
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default edit

    Eclipse lets me set the command line arguments to run from ide

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    To get rid of one warning, use a parameterized List, i.e.,
    Java Code:
    List<String> lstArgs = new LinkedList<String>();

Similar Threads

  1. Inside a Timer thread loop,how to refresh a JTable in swing
    By neha_negi in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-04-2009, 01:45 AM
  2. Loop System print or println statements
    By Singing Boyo in forum New To Java
    Replies: 6
    Last Post: 03-22-2009, 03:52 AM
  3. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-18-2008, 11:06 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. how to print output on same line in 'while loop'?
    By acidblue in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 02:30 AM

Posting Permissions

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