title: Invalid Character Constant in Java?
body: <p>Here is my code:</p>
  
  <pre><code>import java.util.Scanner;
  import javax.swing.JOptionPane;
  import java.text.DecimalFormat;
  
  /*
  
  Medium Speed
  Air 1100 feet per second
  Water 4900 feet per second
  Steel 16,400 feet per second
  
  Write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will
  travel in the medium. The program should then display the amount of time it will take.
  You can calculate the amount of time it takes sound to travel in air with the following formula:
  
  Time = Distance / 1100
  You can calculate the amount of time it takes sound to travel in water with the following formula:
  
  Time = Distance / 4900
  You can calculate the amount of time it takes sound to travel in steel with the following formula:
  
  Time = Distance / 16400
  */
  
  public class SpeedOfSound
  {
      public static void main(String[] args)
        {
  
  
          String input;   
          char timeTraveled;
  
          Scanner keyboard = new Scanner(System.in);
  
  
          double distance;
          double time;
          double time2;
          double time3;
          time = (distance/ 1100);
          time2 = (distance/ 4900);
          time3 = (distance/ 16400);
          DecimalFormat formatter = new DecimalFormat("#0.00");
  
  
  
                  System.out.println("Enter air, water, or steel: ");
                  input = keyboard.nextLine();
                  System.out.print("Enter distance: ");
                  distance = keyboard.nextDouble();
  
  
  
                 switch(timeTraveled)
                 {
                  case 'air':
  
                  System.out.printf("The total time traveled is " + formatter.format(time) + ".");
                  break;
  
                  case "water":
  
  
                  System.out.printf("The total time traveled is " + formatter.format(time2) + ".");
                  break;
  
                  case "steel":
  
  
                  System.out.printf("The total time traveled is " + formatter.format(time3) + "seconds.");
                  timeTraveled = input.charAt(0);
                  break;
                  keyboard.close();
      }
  } // main()
  }  // class SpeedOfSound
  </code></pre>
  
  <p>Why is <code>case 'air':</code> giving me the error <code>invalid character constant</code> twice? My professor has a different example for a different program and it's almost the same as what I'm doing but he doesn't get the error. Why do I get this error?</p>