Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-12-2008, 08:14 PM
thieflock thieflock is offline
Newbie
 
Join Date: Jun 2007
Posts: 14
Rep Power: 0
thieflock is on a distinguished road
Default I need array help.

I appreciate Keller trying to help earlier but that code is only good for the length of the string and not the number of integers.

Anyway, I need to basically rewrite the ArrayList method. I can't seems to get the addMethod code worked out.

I really only need someone to help me out with the concept and not the accual code.

So far the user it prompted with a JOptionPane.showInput... and I take that string, pass it into a new scanner and try to use a .hasNext to count the number of integers in the string. it doesn't do the count, the method code goes as follows:

java Code:
  1. // find how many integers are in the string
  2. int index = 0;
  3. while (console.hasNext()) {
  4.    index++;
  5. }
  6.  
  7. // create a new array with the index that is counted in the loop above
  8. int[] array = new int[index];
  9. int i = 0;
  10.  
  11. // loop through the string again and assign each integer to the array
  12. while (console.hasNextInt()) {
  13.    array[i] = console.nextInt();
  14. }
The first count "index" it not counting in that while loop and I do not know why. Any ideas? If you have a better idea to do this I would appreciate it.

Last edited by Jaan; 04-13-2008 at 05:35 AM. Reason: Please use tags when you're posting your codes!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-14-2008, 10:02 PM
gszauer's Avatar   
gszauer gszauer is offline
Programmer
 
Join Date: Nov 2007
Location: Florida
Age: 18
Posts: 113
Rep Power: 3
gszauer is on a distinguished road
Default Re: I need array help.

.........
The answer to your problem is the java.util.regex; better known as java's regular expression engine.
(\d+) <- Serches for 1 or more digit's
[0-9] <- Same deal
Google regular expressions.
__________________
Quote:
Originally Posted by ~Aristotle
It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array manipulation Question in C++ JJJIrish05 C and C++ 1 03-08-2008 02:06 PM
Problems passing a serialized array in a session variable gszauer PHP Forum 3 02-15-2008 11:18 AM
Usage of array structures to increment letter instances of text Yuriy M C and C++ 2 09-13-2007 10:49 AM
fread into array position kenna C and C++ 0 08-17-2007 08:03 AM
Python 2D array question annannienann Delphi/Python 3 04-23-2007 04:36 PM


All times are GMT -5. The time now is 11:29 PM.

Contest Stats

dargueta ........ 93.00000
John ........ 87.50000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads