为什么此代码位中使用的三元运算有效?
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 ) { }
}
但它不适用于这个:
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
}
}
?
编辑:我想我现在明白了。如果我将第二个功能更改为:
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;
}
然后它工作。感谢大家