美文网首页
聪聪工作室---JAVA入门小程序---运算符判断

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

作者: 繁花流水congcong | 来源:发表于2016-07-12 16:56 被阅读20次

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);

}

}

相关文章

网友评论

      本文标题:聪聪工作室---JAVA入门小程序---运算符判断

      本文链接:https://www.haomeiwen.com/subject/bbcsjttx.html