title: How to use char from keyboard in if statement [Java]
body: <p>I am having a bit of a problem with my code. I need to make a temperature conversion from Celsius to Fahrenheit and vice-versa with the user choosing either &quot;F&quot; or &quot;C&quot; (lower or upper case) but cannot seem to figure out how to do it properly. I don't know how to have it recognize that the variable is supposed to be entered via the keyboard.</p>
  <pre><code> Scanner Keyboard = new Scanner(System.in); 
   System.out.println(&quot;Type C to convert from Fahrenheit to Celsius or&quot; + 
          &quot;F to convert from Celsius to Fahrenheit.&quot;); 
   char choice = Keyboard.nextLine().charAt(0);
   //Get user input on whether to do F to C or C to F 
   if (choice == F) //Fahrenheit to Celsius
   { 
        System.out.println(&quot;Please enter the temperature in Fahrenheit:&quot;); 
        double C = Keyboard.nextDouble();
        double SaveC = C;
        C = (((C-32)*5)/9);
        System.out.println(SaveC + &quot; degrees in Fahrenheit is equivalent to &quot; + C + &quot; degrees in Celsius.&quot;); 
   } 
   else if (choice == C) 
   { 
        System.out.println(&quot;Please enter the temperature in Celsius:&quot;); 
        double F = Keyboard.nextDouble(); 
        double SaveF = F;
        F = (((F*9)/5)+32); 
        System.out.println(SaveF +&quot; degrees in Celsius is equivalent to &quot; + F + &quot; degrees in Fahrenheit.&quot;); 
   } 
   else if (choice != C &amp;&amp; choice != F) 
   { 
        System.out.println(&quot;You've entered an invalid character.&quot;);
   } 
  </code></pre>