JAVA第五次作业

目录

1.二维数组实现杨辉三角

2.统计成绩

3.客车售票

1.二维数组实现杨辉三角

public class Zy1 {
    public static void main(String[] args) {        
        int arr[][] = new int[11][10];
          for (int i = 0; i < arr.length; i++) {
           for (int j = 0; j < i; j++) {
            if (j == 0 || j == i) {
             arr[i][j] = 1;
            } else {
             arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
            }
            System.out.print(arr[i][j] + "\t");
           }
           System.out.println();
          }
    }}

 

 

2.统计成绩
统计学生成绩,输入学生的学号及语文、数学、英语成绩,输出学生各科成绩信息、平
均成绩和总成绩,

import java.util.Scanner;
public class ZY2 {
        public static void main(String[] args) {
            System.out.println("请输入第3个学生的编号:");             
                Scanner scanner=new Scanner(System.in);       
                      int a=scanner.nextInt();
                        System.out.println("请输入语文成绩:");
                        int b=scanner.nextInt();
                        System.out.println("请输入数学成绩:");
                        int c=scanner.nextInt();
                        System.out.println("请输入英语成绩:");
                        int d=scanner.nextInt();
                        int arr[]=new int [] {b,c,d};
                        System.out.println("学生成绩结果如下");
                        System.out.println("---------------------------");   
                        System.out.println("学生编号 语文成绩 数学成绩 英语成绩 平均分 总分");
                        System.out.print(a+"      ");
                        int count=0;
                        for(int i=0;i<3;i++){
                        count=count+arr[i];                    
                        System.out.print(arr[i]+"     ");//将数组中每个元素输出                          
                        }                        
                        double avg=0;
                        avg=(int)count/arr.length;                            
                        System.out.print(""+avg);
                        System.out.print(" "+count);
        }}

 

 

3.客车售票
一辆大巴有9排4列的座位,模拟这辆客车的售票过程(1代“有票”,
0代表“无票”)

import java.util.Scanner;
 
public class ZY3 {
    public static void main(String[] args) {
        int zuo[][] = new int[9][4];// 定义二维数组
        for (int i = 0; i < 9; i++) {// for循环开始
            for (int j = 0; j < 4; j++) {// for循环开始
                zuo[i][j] = 1;// 初始化二维数组
            }
        }
        while (true) {// 开始售票
            // 输出标题
            System.out.println("     简单客车售票系统" + "\n  9排4列的大巴车开始售票");
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 4; j++) {
                    System.out.print(zuo[i][j] + "\t");// 输出售票信息
                }
                System.out.println();// 输出换行符
            }
            // 创建扫描器,用来进行用户输入
            Scanner sc = new Scanner(System.in);
            // 提示用户输入信息
            System.out.print("请输入要预定的坐位行号:");
            int row = sc.nextInt();// 得到坐位行数
            // 提示用户输入信息
            System.out.print("请输入要预定的坐位列号:");
            int column = sc.nextInt();// 得到坐位列数
            zuo[row - 1][column - 1] = 0;// 标记售出票状态
    }
}}


————————————————

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值