5 Replies - 29547 Views - Last Post: 28 June 2011 - 08:31 AM Rate Topic: -----

#1 Rikka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 21-June 11

question on searching an array by using the inputted integer from user

Posted 28 June 2011 - 08:21 AM

I have difficulties in finding the integer entered by a user in an array. Thank you.
Is This A Good Question/Topic? 0
  • +

Replies To: question on searching an array by using the inputted integer from user

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: question on searching an array by using the inputted integer from user

Posted 28 June 2011 - 08:24 AM

Have a look at this arrays tutorial.

Now break down the problem:
-Do you know how to loop through an array?
-Do you know how to compare two ints?
-Do you know how to use an if statement?

Make some effort to solve your problem and explore the steps I outlined above. We will be happy to help you more once you make a good faith attempt at solving the problem.
Was This Post Helpful? 0
  • +
  • -

#3 Rikka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 21-June 11

Re: question on searching an array by using the inputted integer from user

Posted 28 June 2011 - 08:26 AM

Yes I know how to. I'm just having difficulties in this search thing if its an integer.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: question on searching an array by using the inputted integer from user

Posted 28 June 2011 - 08:28 AM

You can test to see if a String is an int by using the Integer.parseInt() method and a try-catch. Integer.parseInt() throws a NumberFormatException if you pass an invalid int. So:
try{ Integer.parseInt(someString); }
catch(NumberFormatException e){ /*invalid int*/ }


Was This Post Helpful? 0
  • +
  • -

#5 Rikka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 21-June 11

Re: question on searching an array by using the inputted integer from user

Posted 28 June 2011 - 08:30 AM

Hmm You see, The integers being placed in the array is an input from the user.
I already sorted them ascending and descending.
Then from that array all integers entered by the user, the user is asked to enter an integer that will search if its in the array. :)
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: question on searching an array by using the inputted integer from user

Posted 28 June 2011 - 08:31 AM

So have you made a good faith attempt? Show us your code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1