I have a input file named file.txt with the contents
Zone
1.0 2.0 3.0
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
Zone
5.0 2.0 3.0
25.0 3.0 4.0
15.0 2.0 3.0
25.0 3.0 4.0
41.0 2.0 3.0
25.0 3.0 4.0
16.0 2.0 3.0
25.0 3.0 4.0
15.0 2.0 3.0
25.0 3.0 4.0
41.0 2.0 3.0
Zone
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
I am looking for a output like
I have a input file named file.txt with the contents
Zone
1.0 2.0 3.0
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
1.0 2.0 3.0
2.0 3.0 4.0
Zone
5.0 2.0 3.0
25.0 3.0 4.0
15.0 2.0 3.0
25.0 3.0 4.0
41.0 2.0 3.0
25.0 3.0 4.0
16.0 2.0 3.0
25.0 3.0 4.0
I am looking for a output like
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=[]
However, I am getting the values of x=[] for zone=2 from the starting of zone=1, as I am using x.add(scanner.nextDouble()).
Please help me. Thanks in advance.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package boltcal1103;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.String;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author admin
*/
public class ZoneFille14 {
public static void main(String[] args) throws FileNotFoundException {
List<String> s1=new ArrayList<String>();
List<Double> x = new ArrayList<Double>(); //Defining double arraylist for Fx
List<Double> y = new ArrayList<Double>(); //Defining double arraylist for Fy
List<Double> z = new ArrayList<Double>(); //Defining double arraylist for Fz
String word="Zone",line=null;
int count = 1;
double x1=0.0;
String s="Zone";
Scanner scanner = new Scanner(new FileReader("file.txt"));
while (scanner.hasNext())
{
line = scanner.next();
if (line.equals(word))
{
System.out.println("zone=:"+count);
for(int i = 0; i<8 ; i++)
{
x.add(scanner.nextDouble());
y.add(scanner.nextDouble());
z.add(scanner.nextDouble());
}
System.out.println(x);
System.out.println(y);
System.out.println(z);
count++;
}
}
scanner.close();
}