The lexical analyzer must accept a string with the same number of a and b.
The program accepts any chain that has a and b.
public static int i;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String s;
System.out.println("Input something to lexically analyze: ");
s = input.next( );
int j = 0;
if(s.charAt(i)=='a'||'b'){
for (int i = 1; i < s.length(); i++) {
j++;
if(i==j){
System.out.println("cadena correcta");
}
}
}
else {
System.out.println("cadena incorrecta\n");
System.exit(0);
}
}
}
I am trying to count how many times a and b is repeated to know if you have the same number of letters but it has not worked for me.