I want to read a file into an array - we will call it myArray1. I want to split the file at a certain point, and make the rest of the file go to myArray2. I have tried using while loop inside a for loop to do this, my attempt is show below. Please do note that I am new to java. Thankyou for your help.
Note: There are 35 numbers in the file
import java.util.*;
import java.math.*;
import java.io.*;
class Test{
public static void main(String[] args) throws Exception{
Integer[] myArray1 = new Integer[20];
Integer[] myArray2 = new Integer[15];
//Reading Rectangle and Triangle address from file 3.....
Scanner reader = new Scanner(System.in);
System.out.println("Please specify file name:");
String fileName = reader.nextLine();
File inputFile = new File(fileName);
reader = new Scanner(inputFile);
/*
IMPORTANT: We are splitting up File . The first 20 numbers of file will go to myArray1, and the next 15 goes to myArray2*/
for(int i = 0; i<35; i ++){
while (i<20){
myArray1[i] = reader.nextInt();
System.out.println("Rectangle is" +myArray1[i]);
i++;
}
while (i>19){
myArray2[i] = reader.nextInt();
System.out.println("TTTTTTTTTT is" +myArray2[i]);
i++;
}
}
}
}
The first bit works - putting the first 20 numbers to myArray1, but the second bit doesn't. I can't work out why.

New Topic/Question
Reply




MultiQuote






|