说这是我的代码:
String name = in1.next();
int highNumber = in1.nextInt();
int lowNumber = in1.nextInt();
System.out.println(name +" " + highNumber +" " + lowNumber);
name
如果不是 12 ,有没有办法可以在前面添加一个数字?或者有没有办法创建一个ArrayList
做同样的事情?
我需要从一个文件中获取 12 行,每行都带有name
, highNumber
,并且lowNumber
我希望能够单独操作每个等式,也可以完全操作。
文件:
Edward 33 22
Billy 22 14
Fred 44 43
Jim 12 1
Andy 3 2
...
预期输出:
Name High Low Average Range
--------------------------------------------------------------------------
Billy 22 14 18 8
...
Total Averages
Total Highs
Total Lows
替代做这样的事情:
String name2 = in1.next();
int highNumber2 = in1.nextInt();
int lowNumber2 = in1.nextInt();
String name3 = in1.next();
int highNumber3 = in1.nextInt();
int lowNumber3 = in1.nextInt();
String name4 = in1.next();
int highNumber4 = in1.nextInt();
int lowNumber4 = in1.nextInt();
...
String name12 = in1.next();
int highNumber12 = in1.nextInt();
int lowNumber12 = in1.nextInt();
我被限制使用Scanner
and PrintWriter
。:(