java - 从输入文件java中分割二维数组
问题描述
有人可以帮我吗?共3个部分,第1部分是第一个索引,子顺序部分是后面每5个索引的总和。不知道为什么我不断收到异常错误。
public class Main {
public static void main(String[] args) throws IOException {
double min, max, sum = 0, avg = 0;// DecimalFormat class is used to format the output
DecimalFormat df = new DecimalFormat(".0");// DecimalFormat class is used to format the output
DecimalFormat df1 = new DecimalFormat(".00");
int rows = 0, cols = 0;
String names[] = null;
double scores[][] = null;
double scoressec[][] = null;
BufferedWriter writer = null;
try { //Opening the input file
Scanner sc = new Scanner(new File("Input.txt"));//Reading the no of rows and columns
rows = sc.nextInt();//check
cols = sc.nextInt();
names = new String[rows];
scores = new double[rows][cols - 1];
scoressec = new double[rows][0];
/* Getting the data from the input file
* and populate those values into array
*/
for (int i = 0; i < rows; i++) {
names[i] = sc.next();
for (int j = 0; j < cols - 1; j++) {
scores[i][j] = sc.nextDouble();
if (j == 0) {
scoressec[i][1] = scores[i][1];
} else if (j == 5) {
scoressec[i][2] += scores[i][j] - scores[i][1];
} else {
scoressec[i][3] += scores[i][j] - scoressec[i][2];
}
}
} //closing the input file`
解决方案
推荐阅读
- java - Java 编译 UNIX - 类路径使用
- python - 解决 python 列表中的内存错误问题或更聪明的 Numpy 方法
- google-cloud-platform - 有没有办法为 http/https 网站使用 GCP TCP 负载平衡和 IPv6?
- android - SQLite 表未正确创建
- javascript - 通过单击表格标题根据单元格背景颜色对表格进行排序
- swift - 如何检测 UITableView 中处于选定状态的最后一行?
- ios - 将“GoogleSignIn”添加到框架会崩溃,并出现“未找到架构 x86_64 的符号”
- python - 继承具有验证的基本烧瓶形式
- spring - 在哪里使用@Transactional注解和@Repository注解
- c++ - 反转斐波那契数列