The error for the following code is:
StringCharacter.java:13: error: bad operand types for binary operator '!=' if(st.charAt(i) != " ") ^ first type: char second type: String 1 error
// program to demonstrate String class public class StringCharacter{ public static void main(String args[]){ String st = "This is my first program."; int count = 0; int length = st.length(); // returns length of string // increment count for each character excluding spaces for(int i = 0; i < length; i++){ if(st.charAt(i) != " ") count++; } System.out.println("The number of characters in this string is: " + count); } }