聪聪工作室---JAVA入门小程序---运算符判断

2016-07-12  本文已影响20人  繁花流水congcong

We'll say that a number is "teen" if it is in the range 13..19 inclusive. Given 2 int values, return true if one or the other is teen, but not both.

solution:

package congcong;

public class loneTeen {

public static void main(String[] args) {

// TODO Auto-generated method stub

boolean a=loneTeen(13,99);

boolean b=loneTeen(21,19);

boolean c=loneTeen(13,13);

System.out.println(a);

System.out.println(b);

System.out.println(c);

}

private static boolean loneTeen(int a, int b) {

// TODO Auto-generated method stub

boolean aTeen=(a>=13&&a<=19);

boolean bTeen=(b>=13&&b<=19);

return (aTeen&&!bTeen)||(!aTeen&&bTeen);

}

}

上一篇 下一篇

猜你喜欢

热点阅读