-1

Here's the relevant code:

public static void printBoarders (Territory x) 
{
    int t = 0 ; 
    int n = 0 ; 
    for (int i = 0; i<x.borders.length; i++)
    {
        if (x.borders[i] == -1) 
            t = i ; 
    }
    for (int j = 0; j<x.borders.length; j++) 
    {
        if (x.borders[j] == 1) 
            n++ ;
    }

    Territory.translate (t) ;
    System.out.print (" has " + n + " borders: ") ;
    Territory.translate (x.borders) ;
    System.out.println (" ") ; 
}

When I run this, I get everything on one line without a line break. Why isn't the System.out.println (" ") ; creating a line break?

Here is an example of what the output winds up being:

Northwest Territory, Alberta, Kamchatka, hidavid-names-macbook-pro:~ davidname$

EDIT: the problem was that this method was never being invoked. A different one which i was replacing was. All is well.

David
  • 14,569
  • 34
  • 78
  • 107
  • 4
    It looks to me like that output doesn't come from the code you're showing here. Where is the "has" and the "borders:"? – Carl Norum Mar 24 '10 at 17:55

7 Answers7

2

None of the code you're showing is what's outputting "Northwest Territory, Alberta, Kamchatka".

What does .translate() do? It's got to be in there.

Dean J
  • 39,360
  • 16
  • 67
  • 93
1

i dont see it printing has " + n + " borders: either, so im going to say the code is never executed for some reason

mkoryak
  • 57,086
  • 61
  • 201
  • 257
1

I can see only

System.out.print (" has " + n + " borders: ") ;

Actually I don't understand why you see any other output then

" has 5 borders: "

Roman
  • 64,384
  • 92
  • 238
  • 332
1

The code snippit above would start a new line. The problem is that the method printBoarders isn't being invoked.

David
  • 14,569
  • 34
  • 78
  • 107
0

I believe it's starting from the middle of the line where the last System.out.print call left it.

from the docs for PrintWriter, e.g.

public void println(String x)

Prints a String and then terminates the line.

Roman
  • 64,384
  • 92
  • 238
  • 332
Steve B.
  • 55,454
  • 12
  • 93
  • 132
0

Only the last print is println, the first is just print so only the space " " is printed to a new line at the end...

EDIT: You mean when you call it multiple times?Y

Tamar
  • 2,016
  • 1
  • 15
  • 26
  • if it were printed on a new line then davvid-names-backboo-pro:~davidname$ would be printed below it. – David Mar 24 '10 at 17:56
0

Just quickly scanning this code, it look like the println() does seem to be reached. Actually the I'm not even seeing how you got the output you did. Is this the complete code. This is a great case for writing a small unit test.

Vinny
  • 789
  • 8
  • 16