Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-2008, 04:04 PM
Member
 
Join Date: Nov 2008
Posts: 20
Rep Power: 0
TheRocket is on a distinguished road
Default Scanner Class...
Hey,

I am making a program which asks the user to input a word and then a sentence, the program then takes the word and inputs in at a certain location in the sentence. Example:

String word = “example”;
String sentence = “An example sentence”;

String one = word(sentence,word,0);
“example An example sentence”

String one = word(sentence,word,3);
“An example sentence example”

I am stuck on how to get the program to do this any ideas?

Thanks.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-04-2008, 04:08 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 472
Rep Power: 1
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
you could create an array of Strings and use Delimeter attached to your in.next() that will take each word and put it into the array. After that it's as easy as using Array.set(position, word) (I think thats the method you will need to look it up).

Pretty much you just tell it the word and position in the array to set the word and it will automatically re-organize everything
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-04-2008, 05:07 PM
Member
 
Join Date: Dec 2008
Posts: 33
Rep Power: 0
timkd127 is on a distinguished road
Default
I would use an array and a few methods of the ArrayList class. you can create an object of that class and then simply add strings to an array. you can also place strings into a specific element of an already created and initialized array.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-04-2008, 06:51 PM
Member
 
Join Date: Nov 2008
Posts: 20
Rep Power: 0
TheRocket is on a distinguished road
Default
Hmm, arrays do sound easy any idea how I would go about doing this. If you could create a basic example that would be great.

Thanks
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-04-2008, 07:26 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 472
Rep Power: 1
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
Array[] someArray = new Array[10];

that would create an array with 10 spots[0-9] allocated in memory for use. Read the java docs on delimiter and the String api to get some really useful methods.
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
Java 2 Platform SE 5.0
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-05-2008, 09:48 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Exclamation [] not Array
Originally Posted by xcallmejudasx View Post
Code:
Array[] someArray = new Array[10];
Code:
C:\src_jdk1.5.0_12\java\lang\AbstractMethodError.java
C:\src_jdk1.5.0_12\java\lang\AbstractStringBuilder.java
C:\src_jdk1.5.0_12\java\lang\Appendable.java
C:\src_jdk1.5.0_12\java\lang\ArithmeticException.java
C:\src_jdk1.5.0_12\java\lang\ArrayIndexOutOfBoundsException.java
C:\src_jdk1.5.0_12\java\lang\ArrayStoreException.java
C:\src_jdk1.5.0_12\java\lang\AssertionError.java
C:\src_jdk1.5.0_12\java\lang\AssertionStatusDirectives.java
C:\src_jdk1.5.0_12\java\util\Arrays.java
C:\src_jdk1.5.0_12\java\util\ArrayList.java
Where's
Code:
class Array{}
?

nope, it's [] pretty much anything can have [] which makes an array of whatever it is close to.

I prefer the [] to be appended to the type as the varable is an array of the type declared to be arrayed.

Note that this declaration does not put anything in the array, to do that we either use a loop or in some fashion put Objects or primitive in each unit of the array.

In general, do if((array = null)&&(array.length > 0)&&(array[0] > minValue)&&(array[0] < maxValue)){......}else{error} then wrap the whole code block in a try / catch .....

To do anything cheaper than that will keep you buying books at the mall and placing them to impress people, rather than getting shippable code.

Remember, it always fails on rollout to your boss's most important customer: Even the Great Gates had a bluescreen of death on a network feed.

Code accordingly or keep your resume for flippin burgers current.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan; 12-05-2008 at 09:49 AM. Reason: Array / Arrays
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
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
Scanner Class Performance? jazz2k8 New To Java 1 05-14-2008 02:42 AM
Scanner class question Rgfirefly24 New To Java 5 04-25-2008 12:41 AM
Using Scanner class to read int Java Tip Java Tips 0 01-18-2008 11:50 AM
Scanner class ajaymenon.k Advanced Java 1 11-26-2007 07:01 AM
JDK 5.0 Scanner Class Sircedric88 New To Java 3 07-27-2007 06:55 PM


All times are GMT +2. The time now is 01:29 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org