• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Accepting a String and a String Array in just ONE Method

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a really dumb question! But i thought why not give it a try...

Code a Java method that accepts a String array and a String. The method should return true if the string can be found as an element of the array and false otherwise. Test your method by calling it from the main method which supplies its two parameters (no user input required). Use an array initialiser list to initialise the array you pass. Test thoroughly.


I have started on it and I know it is wrong, could someone please help me. Give me an answer and a explanation, that would be really great because Im so confused at the moment, Thanks!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You're supposed to create a method that takes two parameters. The parameters must be a String[] (string array) and a String.

At the moment your class has three methods:

  • main, which takes one parameter, a String[]
  • Printhelloworld, which takes no parameters
  • printArrays, which takes one parameter, a String[]

  • So, how do you think can you create a method that takes a String[] and a String?

    See this tutorial: Passing Information to a Method or a Constructor.
     
    Mark Do
    Ranch Hand
    Posts: 70
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    ummm......I dont know..!

    I am thinking of making just a



    ???
     
    Marshal
    Posts: 72987
    330
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    No. That is not what is required.
     
    author
    Posts: 23899
    142
    jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Mark Do wrote:ummm......I dont know..!

    I am thinking of making just a



    ???



    Perhaps, you should read the tutorial linked by Jesper. At the very least, you need to to understand how to create a method that takes more than one parameter.

    Henry
     
    Ranch Hand
    Posts: 176
    3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Are you learning from a book ?? try either some book or tutorials
     
    Bartender
    Posts: 2235
    63
    IntelliJ IDE Firefox Browser Spring Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Mark Do wrote:I am thinking of making just a


    I am nitpicking. I know. But the compiler will do that too. It should not be string[]. It should be String[].
    Remember, Java is case sensitive language.
     
    Bartender
    Posts: 10777
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Mark Do wrote:ummm......I dont know..!
    I am thinking of making just a


    Question: Forget arrays for the moment. What would you do if the question asked you to write a method that takes a String and an int? Or two Strings?

    If you don't know how to do that, then you are not ready for this problem; and probably (as Henry says) need to read the tutorials.

    And don't worry: you'll get there; just maybe not today.

    Winston
     
    reply
      Bookmark Topic Watch Topic
    • New Topic