<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "help! how to use Scanner to put items into an array"]]></title>
		<link>http://forums.hotjoe.com/posts/list/1.page</link>
		<description><![CDATA[Latest messages posted in the topic "help! how to use Scanner to put items into an array"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>help! how to use Scanner to put items into an array</title>
				<description><![CDATA[ So, the assignment is to read from an input file, and store each word into an array. Please look at my code and tell me what you think is wrong. btw I'm totally unfamiliar with the Scanner class. I keep getting an error message:<br /> <br /> if(inputFromFile != null){<br />  while (inputFromFile.hasNextLine()) {<br /> String line = inputFromFile.next();<br /> <br /> for (int i = 0; i &lt; array.length; i++)<br /> array[i] = line;<br />    }<br /> }<br /> <br /> for (int i = 0; i &lt; array.length; i++)<br /> System.out.println (array[i]);<br /> <br /> It's just not printing what I want it to print. Help me!]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/616/2344.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/616/2344.page</link>
				<pubDate><![CDATA[Fri, 4 Sep 2009 19:01:56]]> GMT</pubDate>
				<author><![CDATA[ Heather189]]></author>
			</item>
			<item>
				<title>Re:help! how to use Scanner to put items into an array</title>
				<description><![CDATA[ I'm not sure that I'm following your logic, specifically the first "for" loop.  You'll want to keep track of where you are in the array but your first loop just sets the same variable to each array element.  Additionally, you'll want to use "hasNext" since you're parsing tokens, not lines.  Something more like:<br /> <br /> [code]<br /> String[] array = new String[100];    // this can only hold 100 Strings at most<br /> <br /> int arrayIndex = 0;<br /> if(inputFromFile != null){<br />     while (inputFromFile.hasNext()) {<br />         String line = inputFromFile.next();<br /> <br />         if( arrayIndex &lt; array.length )<br />             array[arrayIndex++] = line;<br />         else<br />             System.out.println( "there are too many words for this program" );<br />     }<br /> }<br /> <br /> for (int i = 0; i &lt; arrayIndex - 1; i++)<br />     System.out.println (array[i]);<br /> [/code]<br /> ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/616/2345.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/616/2345.page</link>
				<pubDate><![CDATA[Wed, 9 Sep 2009 08:39:14]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
	</channel>
</rss>
