基礎(chǔ)代碼,就不打注釋了,望采納
成都創(chuàng)新互聯(lián)公司專注于道外網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供道外營(yíng)銷型網(wǎng)站建設(shè),道外網(wǎng)站制作、道外網(wǎng)頁(yè)設(shè)計(jì)、道外網(wǎng)站官網(wǎng)定制、小程序設(shè)計(jì)服務(wù),打造道外網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供道外網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
public?class?Test{
public?static?void?main(String[]?args){
Scanner?sc?=?new?Scanner(System.in);
System.out.println("請(qǐng)輸入數(shù)字");
int?i?=?sc.nextInt();
if(i%2==0){
System.out.println("偶數(shù)");
}else{
System.out.println("奇數(shù)");
}
if(i0){
System.out.println("正數(shù)");
}else?if(i0){
System.out.println("負(fù)數(shù)");
}else{
System.out.println("0");
}
}
}
首先介紹下:質(zhì)數(shù)是除了本身和1以外,沒有質(zhì)因數(shù),就是沒有數(shù)能夠整除之;合數(shù)是除了本身和1以外還有第三個(gè)數(shù)能整除之。
具體示例代碼如下:
public?class?Demo2?{
public?static?void?main(String[]?args)?{
Scanner?scan?=?new?Scanner(System.in);
System.out.print("請(qǐng)輸入一個(gè)數(shù):");
int?num?=?scan.nextInt();
int?index?=?0;//使用一個(gè)數(shù)來(lái)標(biāo)記是質(zhì)數(shù)還是合數(shù)
for?(int?i?=?2;?i??num;?i++)?{
if?(num?%?i?==?0)?{
index++;
}
}
if?(index?==?0)?{//index等于0表示質(zhì)數(shù)
System.out.println("這是個(gè)質(zhì)數(shù)");
}
else?{//index大于0表示合數(shù)
System.out.println("這是個(gè)合數(shù)");
}
}
}
需要注意的是:1不算質(zhì)數(shù)也不算合數(shù)。
問題的思路大概如此,1:根據(jù)姓名去emp表查詢可以統(tǒng)計(jì)一個(gè)count。 2:判斷count是否大于0,如果大于0走els,(count的數(shù)字也可能大于1,所以else里面根據(jù)name獲取一個(gè)list)。3:for循環(huán)循環(huán)list,new一個(gè)tb_teleponebook的實(shí)體,將id set進(jìn)userid字段。保存tb_teleponebook實(shí)體即可。
public?static?void?main(String[]?args)?{
char?name;
double?total?=?0;
int?count?=?0;
double?c?=?0;
int?ftax?=?0;
double?hcost?=?0;
Scanner?kbd?=?new?Scanner(System.in);
System.out.print("Please?enter?item?name,?Q?to?quit:");
name?=?kbd.next().charAt(0);
while?(name?!=?'Q'??name?!=?'q')?{
System.out.print("Please?enter?cost:");
double?cost?=?kbd.nextInt();
if?(!isValid(cost))?{
continue;
}
if?(cost?=?hcost)?{
hcost?=?cost;
}
System.out.print("Please?enter?tax?rate:");
int?tax?=?kbd.nextInt();
if?(tax?==?0)?{
ftax?=?ftax?+?1;
}
c?=?calculateFinalCost(cost,?tax);
System.out.println(name?+?"?costs?"?+?c?+?"?(plus?"?+?tax?+?"%?tax)");
total?=?total?+?c;
count?=?count?+?1;
System.out.print("Please?enter?item?name,?Q?to?quit:");
name?=?kbd.next().charAt(0);
}
if?(count?==?0)?{
System.out.println("No?items?entered");
System.out.println("Thanks?for?shopping?with?JMart");
}?else?{
System.out.println("Average?cost:?"?+?total?/?count);
System.out.println("Number?of?items?with?no?tax:"?+?ftax);
System.out.println("Highest?cost:"?+?hcost);
System.out.println("Thanks?for?shopping?with?JMart");
}
}
public?static?boolean?isValid(double?cost)?{
if?(cost??0)?{
return?true;
}
return?false;
}