/通过本例子可以让你清晰,明了的认识return,break,continue跳转的区别; 你只需要将代码中的return改成其他两种即可实验出效果;/ import java.util.Scanner;public class QiuHeSaBan{ public static void main(String[] args){ int sum = 0;//求和 int par = 0;//平均数 int par1= 0; int par2= 0; int sum1 = 0; int sum2 = 0; System.out.println(“请输入班级:1 or 2 or 3” ); Scanner sc = new Scanner(System.in); int grade = sc.nextInt(); int z = 0; while(z<10){ z++; if(grade1){ System.out.println(“请输入第”+z+“位同学的成绩:”); int num = sc.nextInt(); sum+= num; par=sum/10; }else if(grade2){ System.out.println(“2班同学你好!”); System.out.println(“请输入第”+z+“位同学的成绩:”); int score = sc.nextInt(); sum1+= score; par1=sum1/10; }else if(grade==3){ System.out.println(“3班同学你好!”); System.out.println(“请输入第”+z+“位同学的成绩:”); int sco = sc.nextInt(); sum2+= sco; par2=sum2/10; }else{ System.out.println(“您输入的班级不存在,sb请重新输入!”); return; } } System.out.println(“2班的平均分为:”+par1); System.out.println(“1班的总成绩是:”+sum1); System.out.println(“3班的平均分为:”+par2); System.out.println(“1班的总成绩是:”+sum2); System.out.println(“1班的平均分为:”+par); System.out.println(“1班的总成绩是:”+sum); } }
|