Results 1 to 4 of 4
  1. #1
    space.puffin is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default unable to compare strings and ints

    Hi everyone.

    I'm trying to compare ints and strings for a networked java application, System.out.println("here") won't print, evern when todo = 1.

    At a loss.

    Rob.
    Java Code:
     public static void NetLoad(int todo) {
    
    
            int x[] = new int[4];
            int y[] = new int[4];
            Ships.clear();
            String[] sArray = new String[3];
            System.out.println("todo = " + todo);
            try {
            System.out.println("start cc");
            if (todo == 1) {
                int i = 0;
                for (Ship ship : Ships)
                { sArray[i++] = ship.printShip();
                System.out.println("here");
                }
            }       
            ChatClient cc = new ChatClient(sArray) ;
            System.out.println("end cc");
            if (todo == 0) {
            
            sArray = cc.getS();
            
            for (int j = 0; j < 3; j++) {
                System.out.println("sArray + " +  sArray[j]);
            
            for (int i = 0; i < 4; i++) {
                        x[i] = Character.digit(sArray[j].charAt(i), 10);
                                        }
                    for (int i = 5; i < 9; i++) {
                        int yMinus = (i - 5);
                        y[yMinus] = Character.digit(sArray[j].charAt(i), 10);
    
    
                    }
            
            
                    
              Ships.add(new Ship(x, y));
                    x = new int[4];
                    y = new int[4];
            }
            }       } catch (IOException ex) {
                ex.printStackTrace();
            }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: unable to compare strings and ints

    Quote Originally Posted by space.puffin View Post
    Hi everyone.

    I'm trying to compare ints and strings for a networked java application, System.out.println("here") won't print, evern when todo = 1.

    At a loss.
    I copied the relevant parts of your code:

    Java Code:
             Ships.clear();
                for (Ship ship : Ships)
                { sArray[i++] = ship.printShip();
                System.out.println("here");
                }
    There are no Ships in your Iterable so the body of that loop is never executed ...

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    space.puffin is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: unable to compare strings and ints

    Thanks,

    Sorted :)
    Last edited by space.puffin; 09-27-2011 at 05:52 PM.

  4. #4
    space.puffin is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: unable to compare strings and ints

    posted to a new thread
    Last edited by space.puffin; 09-27-2011 at 07:48 PM.

Similar Threads

  1. how to compare Strings with compareTo?
    By anarelle in forum New To Java
    Replies: 7
    Last Post: 03-10-2011, 02:20 PM
  2. Converting ints to Strings Problem
    By gkoef in forum New To Java
    Replies: 7
    Last Post: 12-06-2010, 02:07 PM
  3. Compare two strings
    By roud9 in forum New To Java
    Replies: 1
    Last Post: 11-05-2010, 12:57 AM
  4. Compare between 2 Strings
    By ChaosINC in forum New To Java
    Replies: 3
    Last Post: 01-17-2010, 12:39 PM
  5. how to compare two strings
    By elizabeth in forum New To Java
    Replies: 7
    Last Post: 08-06-2007, 03:57 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
  •