五月天青色头像情侣网名,国产亚洲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)題的評論 (共 條)

分享到微博請遵守國家法律
普洱| 琼结县| 昌吉市| 瑞安市| 安仁县| 岚皋县| 林周县| 深泽县| 陆丰市| 安多县| 涡阳县| 襄垣县| 大埔县| 武乡县| 新乡市| 邵东县| 临武县| 芒康县| 宣武区| 英超| 江都市| 赤城县| 达拉特旗| 建昌县| 法库县| 余江县| 石嘴山市| 榆中县| 庆城县| 巴中市| 通许县| 闸北区| 北海市| 彭泽县| 上杭县| 小金县| 梁山县| 巴彦淖尔市| 杨浦区| 固安县| 宜兰县|