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

Some easy java help needed.

  • 04-12-2007 5:52pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    Do

    laptopMakes = Keyboard.readString();


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 11,989 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    String[] = Keyboard.readString();

    This looks very much like homework.


  • Advertisement
  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    To be honest Hobbes, he was very close.


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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