lyl890

导航

程序计时,读取二维数组

java程序计时
long startTime=System.currentTimeMillis();
/**
*代码块
*/ 
long endTime = System.currentTimeMillis();
        System.out.println("程序的执行时间:" + (endTime - startTime));

依次读取文件中二维数组:

 FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("src\\o_athletes\\test\\pref0.in");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Scanner scanner =new Scanner(fileInputStream);
        int n=scanner.nextInt();
        System.out.println(n);
        int[][] a=new int[n][n];
        int[][] q=new int[n][n];

        for (int i = 0; i <n; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j]=scanner.nextInt();
                System.out.println(a[i][j]);
            }
        } System.out.println("_____");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                q[i][j]=scanner.nextInt();

                System.out.println(q[i][j]);
            }
        }

 

posted on 2022-05-30 16:23  静静书中仙  阅读(25)  评论(0编辑  收藏  举报