0
から2次元配列を介した文字列と整数の操作配列に変数を格納し、その後manipulation.sample入力することができます:は、私は外部ファイルからデータを取るプログラムを設計しようとしていた外部ファイルのjava
String1 intA1 intA2
String2 intB1 intB2
String3 intC1 intC2
String4 intD1 intD2
String5 intE1 intE2
これらの値を配列から取り出し、次のように操作できるようにしたいと思います。私はStringXおよびコンピューティング(+ intX2(intX1を)/)を取ることができるようにしたい各文字列に対して そして、それぞれのint型の列に私は例のために行うことができるようにしたい(intA1 + intB1 + INTC1 + intD1 + INTE1)
これは私がこれまでに持っていたものです。 ** Java命名規約はまだ私のコースで教えられていないことに注意してください。私はあなたが二回data.txt
を読んで、全く最初の読みの結果を使用していないことを確認
public class 2D_Array {
public static void inputstream(){
File file = new File("data.txt");
try (FileInputStream fis = new FileInputStream(file)) {
int content;
while ((content = fis.read()) != -1) {
readLines("data.txt");
FivebyThree();
System.out.print((char) content);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static int FivebyThree() throws IOException {
Scanner sc = new Scanner(new File("data.txt"));
int[] arr = new int[10];
while(sc.hasNextLine()) {
String line[] = sc.nextLine().split("\\s");
int ele = Integer.parseInt(line[1]);
int index = Integer.parseInt(line[0]);
arr[index] = ele;
}
int sum = 0;
for(int i = 0; i<arr.length; i++) {
sum += arr[i];
System.out.print(arr[i] + "\t");
}
System.out.println("\nSum : " + sum);
return sum;
}
public static String[] readLines(String filename) throws IOException {
FileReader fileReader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<String>();
String line = null;
while ((line = bufferedReader.readLine()) != null)
{
lines.add(line);
}
return lines.toArray(new String[lines.size()]);
}
/* int[][] FivebyThree = new int[5][3];
int row, col;
for (row =0; row < 5; row++) {
for(col = 0; col < 3; col++) {
System.out.printf("%7d", FivebyThree[row][col]);
}
System.out.println();*/
public static void main(String[] args)throws IOException {
inputstream();
}
}
、あなたが持っている問題は何です:私は理解していない、あなたが
String
をどうしたいのですが、2次元アレイを有するとint
の列の合計を計算することは非常に簡単ですか? – nullpointer