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

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入门小程序---运算符判断_第1张图片

你可能感兴趣的:(聪聪工作室---JAVA入门小程序---运算符判断)