Check if the given string is linear or not | Java program for the above approach ; Function to check if the given string is linear or not ; Iterate over string ; If character is not same as the first character then return false ; Increment the tmp ; Driver code ; Given String str ; Function call
import java . util . * ; class GFG { static boolean is_linear ( String s ) { int tmp = 0 ; char first = s . charAt ( 0 ) ; for ( int pos = 0 ; pos < s . length ( ) ; pos += tmp ) { if ( s . charAt ( pos ) != first ) { return false ; } tmp ++ ; } return true ; } public static void main ( String [ ] args ) { String str = " aapaxyayziabcde " ; if ( is_linear ( str ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }