Why does the ternary operation used in this code bit work?
public static void main(String [] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader( System.in ))) {
String hello;
while ((hello = br.readLine()) != null)
System.out.println ( ( hello.matches( ".*h+.*e+.*l.*l.*o+.*" ) ) ? "YES" : "NO"); //this line works
}
catch ( NullPointerException xNE ) { }
}
But it doesn't work with this:
private static void Print_denom( int num ) {
if ( num > 1 ) {
System.out.print(num + " ");
isEven ( num ) ? Print_denom( num>>1 ) : isPrime(num) ? Print_denom(1) : Print_denom(num/Coins.div); //this one doesn't
}
}
?
EDIT: I think I understand now. If I change the 2nd function to something like:
private static int Print_denom( int num ) {
if ( num > 1 ) {
System.out.print(num + " ");
return isEven ( num ) ? Print_denom( num>>1 ) : isPrime(num) ? Print_denom(1) : Print_denom(num/Coins.div);
}
return 0;
}
then it works. Thanks everyone