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.

Some easy java help needed.

  • 04-12-2007 06: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: 12,025 ✭✭✭✭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: 12,025 ✭✭✭✭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: 12,025 ✭✭✭✭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