file.txtという名前の入力ファイルとその内容があります
Zone
Diameter 5
-321 -560 5811
-209 -580 2935
-27 -409 3580
-1075 -220 2847
-1045 206 2827
-19 410 3570
-205 570 2929
-310 565 5768
2.0 3.0 2.0
Zone
Diameter 50
4379 461 23390
484 -264 13447
1259 -516 11969
182 -669 9530
1366 -931 12720
1553 2350 -18702
-3458 6112 -24596
-3606 -6347 -24995
1491 -2267 -18694
1315 835 12740
193 631 9525
12 1252 490 11942
13 520 211 13311
14 4308 -174 23624
私は次のような出力を探しています:
zone=1
x=[1.0 2.0 1.0 2.0 1.0.......2.0 1.0]
similarly y=[]
z=[]
then
zone=2
x=[5.0 25.0 15 25 41 25 16 25]
similarly y=[]
z=[]
ただし、x.add(scanner.nextDouble())を使用しているため、zone=1の先頭からzone=2のx=[]の値を取得しています。
私を助けてください。前もって感謝します。
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package boltcal1103;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author Neha
*/
public class NewMain {
private static ArrayList<Double> x;
private static ArrayList<Double> y;
private static ArrayList<Double> z;
private static String next1;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
//File file1 = new File("file.txt");
Scanner scanner = new Scanner(new FileReader("file1.txt"));
String line=null,word="Zone",next = null, next1=null;
int count=1;
while(scanner.hasNext()) {
line = scanner.nextLine();
if (line.equals(word)) {
if (count > 1) {
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
// int b;
// String next1;
if(scanner.hasNextLine()){
String nextLine1 = scanner.next();
System.out.println("name :"+nextLine1);
// scanner.useDelimiter("\t");
if(scanner.hasNext())
{
// scanner.useDelimiter(" ");
next1 = scanner.next();
System.out.println("value of diameter:"+next1);
//b = Integer.parseInt(scanner.next());
//System.out.println("value of diameter:"+b);
// scanner.useDelimiter("\n");
scanner.nextLine();
}}
System.out.println("zone=:"+count);
count++;
x = new ArrayList<Double>();
y = new ArrayList<Double>();
z = new ArrayList<Double>();
}
else {
// String delims="";
String[] d = line.split("\t");
// System.out.println("zone=:"+d);
x.add(Double.parseDouble(d[0]));
y.add(Double.parseDouble(d[1]));
z.add(Double.parseDouble(d[2]));
// System.out.println("zone=:"+count);
// System.out.println(d[0]);
// System.out.println(d[1]);
// System.out.println(d[2]);
int i;
for(i=0;i<x.size();i++)
{
Double get1 = x.get(i);
// System.out.println("value of x:"+get1);
Double get2 = y.get(i);
Double get3 = z.get(i);
double x1 = get1*get1;
double y1 = get2*get2;
double z1 = get3*get3;
System.out.println("x1:"+x1+"\ty1:"+y1+"\tz1:"+z1);
} }
}
if (count > 1) {
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
}