<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'input help in java' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'input help in java' posted on the 'Java' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sun, 26 May 2013 00:25:12 -0700</pubDate>
    <lastBuildDate>Sun, 26 May 2013 00:25:12 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297252/input-help-in-java/</link>
      <description>I'm having a problem in my program where I'm trying to allow a user to input a single letter. Unfortunately, there is no such thing as &lt;br /&gt;
flav = scan.nextChar() and I was wondering how I can do it.  I'm trying to use it for the following switch case:&lt;br /&gt;
&lt;br /&gt;
  switch ( flav ) &lt;br /&gt;
  {&lt;br /&gt;
       case 'c': &lt;br /&gt;
             kind = COLUMBIAN; &lt;br /&gt;
             break;&lt;br /&gt;
       case 'j': &lt;br /&gt;
             kind = JAVAN; &lt;br /&gt;
             break;&lt;br /&gt;
       case 'b': &lt;br /&gt;
             kind = BRAZILIAN; &lt;br /&gt;
             break;&lt;br /&gt;
       case 'm': &lt;br /&gt;
             kind = MEXICAN; &lt;br /&gt;
             break;&lt;br /&gt;
       default:  &lt;br /&gt;
             s = BAD_FLAVOR;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297252/input-help-in-java/</guid>
      <pubDate>Sat, 26 Mar 2005 09:03:52 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297274/re-input-help-in-java/#297274</link>
      <description>Take the input in, as a string and then convert it to a char using charAt(), in the string class. &lt;br /&gt;
&lt;br /&gt;
In most cases, it is a good idea to take user input as a string as it gives you an opportunity to make sure it is valid data. &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297274/re-input-help-in-java/#297274</guid>
      <pubDate>Sat, 26 Mar 2005 15:23:09 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297285/re-input-help-in-java/#297285</link>
      <description>I typed in the following code to get the letter of each flavor:&lt;br /&gt;
&lt;br /&gt;
flav = scan.nextLine();&lt;br /&gt;
length = flav.length();&lt;br /&gt;
for (i = 0; i &amp;lt; length; i++)&lt;br /&gt;
{&lt;br /&gt;
   flavor = flav.charAt(i);&lt;br /&gt;
						&lt;br /&gt;
   switch (flavor)&lt;br /&gt;
   {&lt;br /&gt;
	case ('c'):&lt;br /&gt;
		kind = coffee.columbian;&lt;br /&gt;
		System.out.println(kind);&lt;br /&gt;
		break;&lt;br /&gt;
							&lt;br /&gt;
        case ('j'):&lt;br /&gt;
	        kind = coffee.javan; &lt;br /&gt;
	        System.out.println(kind);&lt;br /&gt;
	        break;&lt;br /&gt;
	&lt;br /&gt;
        case ('b'):&lt;br /&gt;
	        kind = coffee.brazilian;&lt;br /&gt;
	        System.out.println(kind);&lt;br /&gt;
	        break;&lt;br /&gt;
							&lt;br /&gt;
        case ('m'):&lt;br /&gt;
	        kind = coffee.mexican;&lt;br /&gt;
	        System.out.println(kind);&lt;br /&gt;
	        break;&lt;br /&gt;
							&lt;br /&gt;
        default:&lt;br /&gt;
	        System.out.println("Bad Flavor");&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The problem is that not only does it print out the coffee I want, but it also prints out Bad Flavor and other brands of coffee. What can I do to make it only print out one flavor and not anything else?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297285/re-input-help-in-java/#297285</guid>
      <pubDate>Sat, 26 Mar 2005 17:47:27 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297286/re-input-help-in-java/#297286</link>
      <description>: I typed in the following code to get the letter of each flavor:&lt;br /&gt;
: &lt;br /&gt;
: flav = scan.nextLine();&lt;br /&gt;
: length = flav.length();&lt;br /&gt;
: for (i = 0; i &amp;lt; length; i++)&lt;br /&gt;
: {&lt;br /&gt;
:    flavor = flav.charAt(i);&lt;br /&gt;
: 						&lt;br /&gt;
:    switch (flavor)&lt;br /&gt;
:    {&lt;br /&gt;
: 	case ('c'):&lt;br /&gt;
: 		kind = coffee.columbian;&lt;br /&gt;
: 		System.out.println(kind);&lt;br /&gt;
: 		break;&lt;br /&gt;
: 							&lt;br /&gt;
:         case ('j'):&lt;br /&gt;
: 	        kind = coffee.javan; &lt;br /&gt;
: 	        System.out.println(kind);&lt;br /&gt;
: 	        break;&lt;br /&gt;
: 	&lt;br /&gt;
:         case ('b'):&lt;br /&gt;
: 	        kind = coffee.brazilian;&lt;br /&gt;
: 	        System.out.println(kind);&lt;br /&gt;
: 	        break;&lt;br /&gt;
: 							&lt;br /&gt;
:         case ('m'):&lt;br /&gt;
: 	        kind = coffee.mexican;&lt;br /&gt;
: 	        System.out.println(kind);&lt;br /&gt;
: 	        break;&lt;br /&gt;
: 							&lt;br /&gt;
:         default:&lt;br /&gt;
: 	        System.out.println("Bad Flavor");&lt;br /&gt;
:     }&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: The problem is that not only does it print out the coffee I want, but it also prints out Bad Flavor and other brands of coffee. What can I do to make it only print out one flavor and not anything else?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What is scan an object of? Are you inputting a single character? If yes, it looks like scan takes in the char and the end of line marker, so its length is 2, so it loops twice.  That is just a guess since i don't know what scan is. You can check it, by printing out length. There are classes that handle stuff liek this easily, like BufferedReader.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297286/re-input-help-in-java/#297286</guid>
      <pubDate>Sat, 26 Mar 2005 17:54:46 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297288/re-input-help-in-java/#297288</link>
      <description>All I wanted was the first letter in the name of the flavor.  I used scan as part of the Scanner class where I let a user input the the name of the brand and then the switch case uses the first letter of that brand.  All I need is just find something that would only accept the first letter and nothing else.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297288/re-input-help-in-java/#297288</guid>
      <pubDate>Sat, 26 Mar 2005 18:16:35 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297891/re-input-help-in-java/#297891</link>
      <description>: All I wanted was the first letter in the name of the flavor.  I used scan as part of the Scanner class where I let a user input the the name of the brand and then the switch case uses the first letter of that brand.  All I need is just find something that would only accept the first letter and nothing else.&lt;br /&gt;
&lt;br /&gt;
To get just one character, use scan.next().charAt(0).&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297891/re-input-help-in-java/#297891</guid>
      <pubDate>Thu, 31 Mar 2005 20:43:20 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: input help in java</title>
      <link>http://www.programmersheaven.com/mb/java/297252/297962/re-input-help-in-java/#297962</link>
      <description>: : All I wanted was the first letter in the name of the flavor.  I used scan as part of the Scanner class where I let a user input the the name of the brand and then the switch case uses the first letter of that brand.  All I need is just find something that would only accept the first letter and nothing else.&lt;br /&gt;
: &lt;br /&gt;
: To get just one character, use scan.next().charAt(0).&lt;br /&gt;
: &lt;br /&gt;
Hello;&lt;br /&gt;
&lt;br /&gt;
You need to probably do some input checking maybe something like this...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
class GetFlavor{

public static void main(String [] args){
String input = args[0].toLowerCase();
    char[] inpcheck = input.toCharArray();

if (inpcheck.length &amp;gt; 1){
        System.out.println("You must enter only the first letter of your coffee flavor");
        
}
    else{
        
        chosenFlavor(input.charAt(0));
    }

}
public static void chosenFlavor(char flavor){
    String kind = null;
    
    switch (flavor) 
{ 
case ('c'): 
kind = "coffee.columbian"; 
System.out.println(kind); 
break; 

case ('j'): 
kind = "coffee.javan"; 
System.out.println(kind); 
break; 

case ('b'): 
kind = "coffee.brazilian"; 
System.out.println(kind); 
break; 

case ('m'): 
kind = "coffee.mexican"; 
System.out.println(kind); 
break; 

default: 
System.out.println("Bad Flavor"); 
} 

}

}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I think this will run. &lt;br /&gt;
Hope this helps.&lt;br /&gt;
let us know if you need any additional help.&lt;br /&gt;
&lt;br /&gt;
Ken&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/297252/297962/re-input-help-in-java/#297962</guid>
      <pubDate>Fri, 01 Apr 2005 09:36:07 -0700</pubDate>
      <category>Java</category>
    </item>
  </channel>
</rss>