Straight | Java program for the above approach ; Function to check if N is a Straight Line number or not ; N must be > 99 ; Difference between consecutive digits must be same ; Driver code ; Given Number N ; Function Call
class GFG { static boolean isStraighLineNum ( int N ) { if ( N <= 99 ) return false ; String s = Integer . toString ( N ) ; int d = s . charAt ( 1 ) - s . charAt ( 0 ) ; for ( int i = 2 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i ) - s . charAt ( i - 1 ) != d ) return false ; return true ; } public static void main ( String [ ] args ) { int n = 135 ; if ( isStraighLineNum ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }