while小练习动态录入学生个数,成绩,求总成绩和平均值
package learnday2;
import java.util.Scanner;
* @description:动态录入学生成绩,并求总分和平均值
public class whileDemo01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生个数");
int numStudent = scanner.nextInt();
int sum = 1;
double totalScore = 0;
while (sum<=numStudent) {
System.out.println("请输入第"+sum+"学生的成绩");
double studentScore = scanner.nextDouble();
totalScore +=studentScore;
sum++;
}
System.out.println("总成绩为:" +totalScore);
System.out.println("平均成绩为:"+(totalScore/numStudent));
scanner.close();
}
}
--------------------------------------
switch小练习
package learnday2;标签:case,scanner,--,练习,System,Scanner,while,println,out From: https://www.cnblogs.com/wang1999an/p/16757835.html
import java.util.Scanner;
public class SwitchDemo01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入(1-12)任意一个数字作为月份,以任意字母结束程序");
while (scanner.hasNextInt()) {
int number = scanner.nextInt();
switch (number){
case 12:
case 1:
case 2:
System.out.println("冬季");
break;
case 3:
case 4:
case 5:
System.out.println("春季");
break;
case 6:
case 7:
case 8:
System.out.println("夏季");
break;
case 9:
case 10:
case 11:
System.out.println("秋季");
break;
}
}
scanner.close();
}
}