Question: in JAVA why my code is not running Scanner k = new Scanner(System.in); System.out.println(Please enter a string: ); String str = k.nextLine(); System.out.println(Please enter a
in JAVA
why my code is not running
Scanner k = new Scanner(System.in); System.out.println("Please enter a string: "); String str = k.nextLine(); System.out.println("Please enter a character: "); String input = k.nextLine(); char a = input.charAt(0); int count = 0; for(int i= 0;i<= str.length(); i++) { if(str.charAt(i) == a) count ++; } if(count <= 0) System.out.println("Character not found in the string "); else System.out.println("The number of character appears in the string is " + count);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
