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

Some easy java help needed.

Options
  • 04-12-2007 6:52pm
    #1
    Registered Users Posts: 3,969 ✭✭✭


    Or at least I think it should be easy anyway. Here is some code that will not work, I need to know how to make it work.

    public static void getLaptopDetails(String[] laptopMakes,double[] laptopPrices, int size)
    {



    for (int i=0 ;i < size; i++)
    System.out.println("Please enter the make for laptop " + i);


    String[] = Keyboard.readString();


    }


    I am using Eclipse. I want to put "i" into String[] ( i.e. String ) . I want to be able to type the modles into each element of String .But what eclipse tells me is
    " -Syntax error on token "]",VariabledeclaratorID expected after this token
    -String cannot be resolved
    -Type mismatch , cannot convert type String to String[]

    "


Comments

  • Registered Users Posts: 11,977 ✭✭✭✭Giblet


    Do

    laptopMakes = Keyboard.readString();


  • Registered Users Posts: 3,969 ✭✭✭christophicus


    Thanks for the suggestion. I had tried that before and it says " i cannot be resolved" . Any suggestions about that ?


  • Registered Users Posts: 11,977 ✭✭✭✭Giblet


    Ah, are you enclosing the statements in your for loop?
    public static void getLaptopDetails(String[] laptopMakes,double[] laptopPrices, int size)
    {
        for (int i=0 ;i < size; i++)
        {
            System.out.println("Please enter the make for laptop " + i);
            laptopMakes[i] = Keyboard.readString();
        }
    }
    


  • Registered Users Posts: 3,969 ✭✭✭christophicus


    Thank you man , that was it . I told you it would be a simple stupid thing :D . I spent 3 or 4 hours trying to sort this out :p .


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    String[] = Keyboard.readString();

    This looks very much like homework.


  • Advertisement
  • Registered Users Posts: 3,969 ✭✭✭christophicus


    Yes its for an assignment. Is there a rule against asking for help here? If so I do appologise.


  • Registered Users Posts: 11,977 ✭✭✭✭Giblet


    To be honest Hobbes, he was very close.


  • Registered Users Posts: 3,969 ✭✭✭christophicus


    I just read over the rules, I don't see anything against asking for help. Infact it states the correct procedure to follow with regards looking for help with work/school etc etc.

    Anyway I really do appreciate the help, it means I can move on with the rest of it now.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Giblet wrote: »
    To be honest Hobbes, he was very close.

    It looked very similar to code I've seen a lecturer give before where they intentionally broke the code so that they person would solve it themselves. Up to the Keyboard method. DIT is it?


  • Registered Users Posts: 3,969 ✭✭✭christophicus


    Nope there was no code given, I got to that stage myself. The parameters where given and then text saying what the goal was.

    I go to WIT not DIT.


  • Advertisement
  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    Hobbes wrote: »
    DIT is it?

    DIT don't teach Java in the first year.
    C is the main language used in first year to third year for DT211/228.
    They used to teach Pascal though.


Advertisement