How to find the number of characters in a string in java
<p>Below code outputs only "Enter a string" and accepts user input however, does not display the number of characters in the string. Kindly help!</p>



<pre><code>System.out.println("Enter a string");
Scanner scan = new Scanner(System.in);
String result = scan.nextLine();


try {
 while (a != null) {
  count++;
 }
} catch (Exception e) {
 System.out.println("Invalid string");
}

System.out.println("The number of characters are : " + count);
</code></pre>