五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java作業(yè)的題與答案6:輸入學生的數(shù)目且輸入各個學生的成績題,翻轉(zhuǎn)題,while循環(huán)題

2019-11-12 00:29 作者:詩書畫唱  | 我要投稿

本期看點:

請輸入學生的數(shù)目請輸入各個學生的成績,求和,求平均數(shù)的兩種解法

導讀:有翻轉(zhuǎn)數(shù)的題哦!

1.

//package a1;

//

//

//

//public class a1{

//

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

//

//

// int a=12345;

// int i=0;//因為是起整體的作用,所以必須寫在外面才起作用

//

// int b=a/10000;

// int c=a/1000%10;

// int d=a/100%10;

// int e=a/10%10;

// int f=a%10;

//

//

// i=f*10000+e*1000+d*100+c*10+b;

//

// System.out.println("翻轉(zhuǎn)結(jié)果"+i);

// }

//

//

// }

//

2.

package a1;


import java.util.*;


public class a1{


public static void main(String[] args) {

int i=1;

int he=0;

while(i<=5){System.out.println("請輸入第"+i+"個學生的成績");

Scanner a=new Scanner(System.in);

? ? ? ? ?int b=a.nextInt();

? ? ? ? ?he+=b;

? ? ? ? ?i++;

}

System.out.println(i+"個學生的成績和為"+he);

}



}

3.

請輸入學生的數(shù)目請輸入各個學生的成績,求和,求平均數(shù)的兩種解法

解法一:


package a1;


import java.util.*;


public class a1{


public static void main(String[] args) {System.out.println("請輸入學生的數(shù)目");

int i=1;

double he=0;

Scanner a=new Scanner(System.in);

? ? ? ? int b=a.nextInt();

if(b>0){

while(i<=b){System.out.println("請輸入第"+i+"個學生的成績");

Scanner a2=new Scanner(System.in);

? ? ? ? int c=a2.nextInt();

? ? ? ? ?System.out.println("第"+i+"個學生的成績?yōu)?#34;+c);

? ? ? ? ?

? ? ? ? ?he+=c;

? ? ? ? ?i++;

}

System.out.println((i-1)+"個學生的成績和為"+he);

System.out.println((i-1)+"個學生的平均成績?yōu)?#34;+he/(i-1));}

else{System.out.println("學生的數(shù)目不能為負數(shù)");}

}



}


解法二

package a1;


import java.util.*;


public class a1{


public static void main(String[] args) {System.out.println("請輸入學生的數(shù)目");

int i=1;

double he=0;

Scanner a=new Scanner(System.in);

? ? ? ? int b=a.nextInt();

if(b>0){

while(b>0){System.out.println("請輸入第"+i+"個學生的成績");

Scanner a2=new Scanner(System.in);

? ? ? ? int c=a2.nextInt();

? ? ? ? ?System.out.println("第"+i+"個學生的成績?yōu)?#34;+c);

? ? ? ? ?b--;

? ? ? ? ?he+=c;

? ? ? ? ?i++;

}

System.out.println((i-1)+"個學生的成績和為"+he);

System.out.println((i-1)+"個學生的平均成績?yōu)?#34;+he/(i-1));}

else{System.out.println("學生的數(shù)目不能為負數(shù)");}

}



}




5.

package a1;


import java.util.*;


public class a1{


public static void main(String[] args)?

{System.out.println("請輸入需要結(jié)算金額的顧客數(shù)目");

int i=1;

double he=0;

Scanner a=new Scanner(System.in);

? ? ? ? int b=a.nextInt();

if(b>0){

while(b>0){System.out.println("請輸入第"+i+"個商品的金額");

Scanner a2=new Scanner(System.in);

? ? ? ? int c=a2.nextInt();

? ? ? ? ?System.out.println("第"+i+"個個商品的金額為"+c);

? ? ? ? ?b--;

? ? ? ? ?he+=c;

? ? ? ? ?i++;

}

System.out.println((i-1)+"商品總金額為"+he);

System.out.println((i-1)+"商品的平均金額"+he/(i-1));}

else{System.out.println("數(shù)目要大于0");}

}



}






package a1;

? ? ? ? ??



6.

public class a1{




public static void main(String[] args) {

int i=1;

int he=0;

while(he<=500){


if(i%2==1){


he=he+i;

System.out.println("數(shù)字為"+i+"時,和為"+he);

}

i++;

}System.out.println(i-1);//記得減一

}

}




1.2公里(km)=1200米(m)

Java作業(yè)的題與答案6:輸入學生的數(shù)目且輸入各個學生的成績題,翻轉(zhuǎn)題,while循環(huán)題的評論 (共 條)

分享到微博請遵守國家法律
北辰区| 罗城| 瑞丽市| 武冈市| 梧州市| 谢通门县| 张掖市| 临夏县| 三原县| 双柏县| 黔西县| 吉隆县| 石景山区| 明光市| 营口市| 张掖市| 齐齐哈尔市| 镇平县| 古田县| 秀山| 盘锦市| 怀仁县| 聂拉木县| 都昌县| 南澳县| 宁强县| 南开区| 阳东县| 开原市| 湟源县| 额尔古纳市| 兴山县| 红安县| 天台县| 高阳县| 蒙自县| 汝南县| 潞城市| 开远市| 林芝县| 都江堰市|