在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的时候 就不在管后面的操作数的真假了。 这个Socket程序错在哪里?(新手急求助) 能不能在线程中在创建新的线程 Calendar类的构造方法为何要是protected JAVA中正则表达式 == 和 equals() 有什么区别呢? 如何将数字转换成字符串? 新手求助,我的文件写到32k大小,就再也写不进去了~~~~~~~~~~~`` 加急!!!left join问题: 请教一道SCJP题目的问题 网络传输文件的问题,很急,大侠帮帮忙! 一个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的时候 就不在管后面的操作数的真假了。