Please help me my code doesn't work 😭 😭 java course : Word counting and Character counting 🥺
The output shows Exception in thread "Main" java.stringIndexOutOfBoundException I don't get it what it says import java.util.Scanner; public class Program { public static void main(String[] args) { String str; int size; int charCount=0,wordCount=1; Scanner sc= new Scanner(System.in); System.out.println ("Enter String"); str=sc.nextLine(); System.out.println("String Name \t\t:"+str); size=str.length(); System.out.println("String Length\t:"+size); for(int index=0;index<=size;index++){ if(str.charAt(index)!=' ') { charCount++; } if(str.charAt (index)==' ') { wordCount++; } }//end of for loop System.out.println("Character Count"+charCount); System.out.println("Word Count"+wordCount); } }