Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

stupid java

Options
  • 02-11-2009 11:48am
    #1
    Registered Users 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 Posts: 2,164 ✭✭✭hobochris


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

    I.e

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


  • Registered Users 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 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 Posts: 1,998 ✭✭✭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 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 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 Posts: 2,791 ✭✭✭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 Posts: 2,164 ✭✭✭hobochris


    System.out.Print


Advertisement