Typecasting each character to integer and adding the digit to respective sums
Leftsum += ( int ) ( s . charAt ( i ) - '0' ) ; Rightsum += ( int ) ( s . charAt ( s . length ( ) - 1 - i ) - '0' ) ; } if ( Leftsum == Rightsum ) System . out . println ( " Balanced " ) ; else System . out . println ( " Not ▁ Balanced " ) ; }