scutxiaolaji
scut小辣鸡
2017-09-20 09:04

新人求问Java文件输入输出小问题

  • 图片
  • java
  • class

package Question;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class QuestionTest {

public static void main(String[] args) throws IOException{
    Scanner input = new Scanner(System.in);
    int[] number = new int[5];
    String[] name = new String[5];
    int[][] grade = new int[5][3];
    double[] sum = new double[5];
    for (int i = 0; i < 5; i++) {
        number[i] = input.nextInt();
        name[i] = input.next();
        for (int j = 0; j < 3; j++) {
            grade[i][j] = input.nextInt();
            sum[i] = grade[i][j] / 3;
        }
    }
    File file = new File("Students.txt");
    try (PrintWriter output = new PrintWriter(file);) {
        for (int i = 0; i < 5; i++) {
            output.print(number[i] + "   ");
            output.print(name[i] + "   ");
            for (int j = 0; j < 3; j++) {
                output.print(grade[i] + " ");
            }
            output.println(sum[i]);
        }
    }
}

}
为什么输入
1 s 15 65 98
2 ssd 45 86 59
3 dsa 45 69 84
4 sad59 86 65 35
5 sdds 56 25 35
后输出在txt文件变成了图片这样子图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答

为你推荐