Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

stupid java

  • 02-11-2009 11:48AM
    #1
    Registered Users, Registered Users 2 Posts: 244 ✭✭


    im not used to java but trying to test something, gwtting errors for this line, it will eventually not be needed as the program will read it in from a file but just declaring it as is for now
    layout[][]={{" "," "," ","#","#","#"},{" "," ","#","#"," ","#"," ","#","#","#","#"},{" ","#","#"," "," ","#","#","#"," "," ","#"},{"#","#"," ","$"," "," "," "," "," "," ","#"},{"#"," "," "," ","@","$"," ","#"," "," ","#"},{"#","#","#"," ","$","#","#","#"," "," ","#"},{" "," ","#"," "," ","#",".","."," "," ","#"},{" ","#","#"," ","#","#",".","#"," ","#","#"},{" ","#"," "," "," "," "," "," ","#","#"},{" ","#"," "," "," "," "," ","#","#"},{" ","#","#","#","#","#","#","#"}};
    

    is there anything wrong with it?


Comments

  • Registered Users, Registered Users 2 Posts: 2,164 ✭✭✭hobochris


    How is your variable type declaired? has it been declaired?

    I.e

    String[][] layout = new String[][];
    layout ={{" "," "," ","#","#","#"}, ...


  • Registered Users, Registered Users 2 Posts: 40,038 ✭✭✭✭Sparks


    theliam wrote: »
    is there anything wrong with it?
    Yeah, it's unreadable. We have whitespace for a reason y'know ;)
    layout[][]={
        {" ", " ", " ", "#", "#", "#"}, 
        {" ", " ", "#", "#", " ", "#", " ", "#", "#", "#", "#"}, 
        {" ", "#", "#", " ", " ", "#", "#", "#", " ", " ", "#"}, 
        {"#", "#", " ", "$", " ", " ", " ", " ", " ", " ", "#"}, 
        {"#", " ", " ", " ", "@", "$", " ", "#", " ", " ", "#"}, 
        {"#", "#", "#", " ", "$", "#", "#", "#", " ", " ", "#"}, 
        {" ", " ", "#", " ", " ", "#", ".", ".", " ", " ", "#"}, 
        {" ", "#", "#", " ", "#", "#", ".", "#", " ", "#", "#"}, 
        {" ", "#", " ", " ", " ", " ", " ", " ", "#", "#"}, 
        {" ", "#", " ", " ", " ", " ", " ", "#", "#"}, 
        {" ", "#", "#", "#", "#", "#", "#", "#"}
    };
    

    Also, what are the errors you're getting?


  • Registered Users, Registered Users 2 Posts: 244 ✭✭theliam


    its declared
    char[][] layout;
        layout= new char[20][20];
    

    errors are cannot find symbol class layout, class main
    not a statement
    ; expected
    not a statement
    ; expected
    ...


  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    theliam wrote: »
    its declared
    char[][] layout;
        layout= new char[20][20];
    

    errors are cannot find symbol class layout, class main
    not a statement
    ; expected
    not a statement
    ; expected
    ...

    You have already defined the array above and initialized it therefore you cannot initialize it again.

    Alternatively you can define it as

    char[][] layout ={ <followed by the set of chars in the array>};
    Also you have defined them as char not string yet you are placing strings in them not chars.


  • Registered Users, Registered Users 2 Posts: 244 ✭✭theliam


    lynchie wrote: »
    Also you have defined them as char not string yet you are placing strings in them not chars.

    doh.

    single thingys, right? '#'

    also, when using toCharArray() for strings, will it take endline characters in as well?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 244 ✭✭theliam


    thats sorted but now whem im printing them out using
    System.out.println(layout[i][j]);
    
    it prints each character on a new line...
    how do i make it not do that?
    i have no /n etc.


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    theliam wrote: »
    thats sorted but now whem im printing them out using
    System.out.println(layout[i][j]);
    
    it prints each character on a new line...
    how do i make it not do that?
    i have no /n etc.

    I dont do Java but I'd imagine that you'll have to use a method instead of PrintLn as that's what it's meant to do (print to a new line).


  • Registered Users, Registered Users 2 Posts: 2,164 ✭✭✭hobochris


    System.out.Print


Advertisement