package logical.error;
public class LogicalError {
public static void main(String[] args) {
String word="debugging";
String single_letter="";
int letter_count=0;
for(int i=0;i<word.length();i++)
{
single_letter=word.substring(1,1); // errror
if(single_letter.equals("g"))
{
letter_count++;
}
}
System.out.println("g was fount = "+letter_count+"times");
}
}
after correct:-
package logical.error;
public class LogicalError {
public static void main(String[] args) {
String word="debugging";
String single_letter="";
int letter_count=0;
for(int i=0;i<word.length();i++)
{
single_letter=word.substring(i,i+1); // correct
if(single_letter.equals("g"))
{
letter_count++;
}
}
System.out.println("g was fount = "+letter_count+"times");
}
}