title: Character Counter with a switch statement java
body: <p>I'm writing a character counter programme which reads a line of text and counts the number of vowels, consonant, spaces and punctuation.</p>
  
  <p>I also have to use a switch to increment the count of each.  As it's the first time I've used a switch statement in a programme, I'm not sure if I'm using it correctly within the loop.</p>
  
  <p>As far as I can work out, the issue is with the loop as it compiles, but when it runs, it hangs in the terminal, so I'm assuming the loop is not terminating correctly.</p>
  
  <p>I know my methods of counting the characters are very basic, but that is as per the 
  instructions.</p>
  
  <p>Thanks</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  public class CharacterCounter2
  {
  public static void main(String args[])
  {
  
  Scanner scan = new Scanner(System.in);
  String line = new String(scan.nextLine());
  
  String cons = new String ("bcdfghjklmnpqrstvwxyz");
  String vowels = new String ("aeiou");
  String space = new String (" ");
  String punct = new String(",.;:");
  
  int consCount = 0, vowelCount = 0, spaceCount = 0, pCount = 0, inx = 0;
  char ch = line.charAt(inx);
  
  while (inx &lt;= line.length()-1)
  
  {
  if (cons.indexOf(line.charAt(inx)) != -1)
  ch = 'C';
  else 
  if (vowels.indexOf(line.charAt(inx)) != -1)
  ch = 'V';
  else
  if(line.equals(space))
  ch = 'S';
  if (punct.indexOf(line.charAt(inx)) != -1)
  ch = 'P';
  
  switch (ch)
  {
  case 'C':
  consCount += 1;
  break;
  
  case 'V':
  vowelCount += 1;
  break;
  
  case 'S':
  spaceCount += 1;
  break;
  
  case 'P':
  pCount += 1;
  
  default:
  break;
  
  }
  
  inx = inx ++;
  ch = line.charAt(inx);
  }
  
  
  
  System.out.println("contains" +consCount+" consonants, "+vowelCount+" vowels, " + spaceCount+" spaces" + pCount + "punctuation");
  }
  }
  </code></pre>