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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

stupid java

  • 02-11-2009 10: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 Posts: 2,013 ✭✭✭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