views:

130

answers:

7

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.

A: 

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.

Steve B.
what do you mean?
David
A: 

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
if it were printed on a new line then davvid-names-backboo-pro:~davidname$ would be printed below it.
David
+1  A: 

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

mkoryak
+1  A: 

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
what do you mean thats all you see?
David
@David: that means that you posted wrong peace of code (or it's better to say you posted only part of the code)
Roman
A: 

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
why does it seem like its not reached?
David
+2  A: 

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
+1  A: 

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

David