If there is only 1 character which does not balances then also it is Yes
else if ( po == 1 && ne == 0 ) System . out . println ( " YES " ) ; else if ( po == 0 && ne == - 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }