在JAVA中,这样的同时满足两个条件的程序这么写? 如果 A 是 B 的倍数,那么 A/B==0如果 A + B 是 偶数,那么(A+B)/2==0 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if((A%B)==0 AND (A+B)&2==0){ }else{} if((A%B)==0 AND ((A+B)%2)==0){ }else{} if ( (A%B) == 0 && (A+B)%2 == 0 ){ }else{} if((A%B)==0 AND ((A+B)%2)==0){ }else{} 没有AND是&&,应考虑B==0时,要不会有Excpetion 对应该考虑b=0应该是((B!=0)&&((A/B)==0)&&(((A+B)/2)==0))JAVA没有AND 但有&和&& try{if(a%b==0 && (a+b)%2==0) System.out.println("正确");}else{ System.out.println("不正确");}catch(ArithmeticException e){ System.out.println("不能除0");} public static boolean satisfy(int a, int b) { if(b == 0) return (a == 0); if(a == 0) return (b%2 == 0); return (a%b == 0) && ((a+b)%2 == 0);} if((A!=0)&&(B!=0)&&((A%B)==0)&&((A+B)&2==0)){ }else{} if(B!=0){//B不为0时if((A%B)==0&&(A+B)%2==0){ }else{}}//end if(B!=0)不用管A是否为0,只管B是否为0; 放到.java里一试就知道啦......... 我考虑了除零的问题,为什么不给我分?完整例子class Test{public static void main(String[] args)throws IOException{int a,b;System.in.read(a);System.in.read(b);try{if(a%b==0 & (a+b)%2==0)System.out.println("正确");}else{System.out.println("不正确");}catch(ArithmeticException e){System.out.println("不能除0");}}}还有需要说明的,如果想使用a%b 和 (a+b)%2运算结果,建议不要使用&&比如if( (c=a%b)==0 &&(d=(a+b)%2==0){c=d++ ;}同if( (c=a%b)==0 &(d=(a+b)%2==0){c=d++ ;}的结果可能是不一样的。因为 &&前面表达式如果是false那么就不再考虑后面的表达式了 ||的用法相同 当前面的是 true的时候 就不在管后面的操作数的真假了。 请问能在GridLayout的指定位置添加一个组件吗? 关于java键盘输入的问题 菜鸟搞不懂 大哥帮下 applet的问题。 javaBean连接SQLServer2000的问题 编码:utf8, gbk, iso8859-1出现问题,高手指点!!! 入门程序的问题?请大家帮忙 请教高手applet如何用socket和servlet进行通讯?(最好有项细代码) 匿名类 java InetAddress 的 getLocalHost 与 getByName 对于本机有什么区别? 关于String类实例方法判断字符是否为汉字; 一个java作数据库方面的问题 jar包双击执行
{
}
else
{}
if((A%B)==0 AND ((A+B)%2)==0)
{
}
else
{}
{
}
else
{}
if((A%B)==0 AND ((A+B)%2)==0)
{
}
else
{}
应该是((B!=0)&&((A/B)==0)&&(((A+B)/2)==0))
JAVA没有AND 但有&和&&
if(a%b==0 && (a+b)%2==0)
System.out.println("正确");
}
else{
System.out.println("不正确");
}
catch(ArithmeticException e){
System.out.println("不能除0");
}
if(b == 0)
return (a == 0);
if(a == 0)
return (b%2 == 0);
return (a%b == 0) && ((a+b)%2 == 0);
}
{
}
else
{}
if((A%B)==0&&(A+B)%2==0)
{
}
else
{}
}//end if(B!=0)不用管A是否为0,只管B是否为0;
完整例子
class Test{
public static void main(String[] args)
throws IOException{
int a,b;
System.in.read(a);
System.in.read(b);
try{
if(a%b==0 & (a+b)%2==0)
System.out.println("正确");
}
else{
System.out.println("不正确");
}
catch(ArithmeticException e){
System.out.println("不能除0");
}
}
}
还有需要说明的,如果想使用a%b 和 (a+b)%2运算结果,建议不要使用&&比如
if( (c=a%b)==0 &&(d=(a+b)%2==0){c=d++ ;}
同
if( (c=a%b)==0 &(d=(a+b)%2==0){c=d++ ;}
的结果可能是不一样的。
因为 &&前面表达式如果是false那么就不再考虑后面的表达式了 ||的用法相同 当前面的是 true的时候 就不在管后面的操作数的真假了。