Check if a string follows a ^ nb ^ n pattern or not | Java code to check a ^ nb ^ n pattern ; Returns " Yes " str is of the form a ^ nb ^ n . ; check first half is ' a ' and other half is full of ' b ' ; Driver code ; Function call
import java . io . * ; class GFG { static String isAnBn ( String str ) { int n = str . length ( ) ; if ( ( n & 1 ) != 0 ) return " No " ; int i ; for ( i = 0 ; i < n / 2 ; i ++ ) if ( str . charAt ( i ) != ' a ' || str . charAt ( n - i - 1 ) != ' b ' ) return " No " ; return " Yes " ; } public static void main ( String [ ] args ) { String str = " ab " ; System . out . println ( isAnBn ( str ) ) ; } }