第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

判斷一個數(shù)是偶數(shù),為何我的方法不對?

我一開始想到的方法是,假設(shè)a是一個偶數(shù),那么 a/2 取整,然后乘于2 必然完全等于 a ,可是編譯器認(rèn)為是不對的,代碼如下,請指正:

public class oushu{

? ? public static void main(String[] args){

? ? ? ? int one=20;

? ? ? ? double pan=one/2;

? ? ? ? int panduan=(int)pan;

? ? ? ? if((panduan*2)==one){

? ? ? ? ? ? System.out.println("one 是整數(shù) ");

? ? ? ? }

? ? ? ? System.out.println("one 不是整數(shù)");

? ?}

}

正在回答

3 回答

package oushu;


public class oushu {

public static void main(String[]args){

int one=20;

double x=one/2;

if(x*2==one){

System.out.println("one是偶數(shù)");}

else {System.out.println("one不是偶數(shù)");

}

}

}

我剛開始學(xué)很多都不太明白但是這個好像可以用

0 回復(fù) 有任何疑惑可以回復(fù)我~
public?class?oushu
{
????public?static?void?main(String[]?args)
????{
????????int?one=20;
????????if?(?0?==?(?one?%?2?)?)?{
????????????System.out.println(?"one?是偶數(shù)"?);
????????}
????????else?{
????????????System.out.println(?"one?不是偶數(shù)"?);
????????}
???}
}


1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

有時蔚藍(lán) 提問者

感謝你的回復(fù),但這是用的取余的方法,我想請問取整的方法,應(yīng)該如何?
2015-02-27 回復(fù) 有任何疑惑可以回復(fù)我~

我知道,答案是用的取余;從邏輯上思考,我的方法也是對的吧,可是為什么無法通過執(zhí)行?以為是網(wǎng)頁功能不夠完全,我下載了JDK 8u31,仍然無法執(zhí)行。。。求教這種方法的代碼!

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

判斷一個數(shù)是偶數(shù),為何我的方法不對?

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號