Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Create two dimensional array from a one dimensional array

1. ## Create two dimensional array from a one dimensional array

I am trying to add fractions from a file. I have managed to put each line into a string array.
example file:
3/2
4/3
5/6

array: 3/2, 4/3, 5/6

How can I split up these numbers so that a have a dimensional array that would be

3 ,2
4, 3
5,6

My code so far:

```import java.util.Scanner;
import java.io.FileNotFoundException;
import java.lang.String;
import java.io.File;
import java.io.FileInputStream;

public class Assignment1{

public static void main(String [] args){
Scanner inputFile = null;
try {
inputFile = new Scanner(new FileInputStream("fractions.txt"));
}
catch (FileNotFoundException e) {
System.exit(0);
}

String[]test = new String[100];
String[][]fractions = new String [100][2];
int count = 0;

//
//while(inputFile.hasNextLine()){
//   count++;
//    inputFile.nextLine();
//}

for(int i = 0; i<=31; i++){
test[i]=inputFile.nextLine();
}

for(int i = 0; i<=31; i++){
fractions[i][i+1]= test

}

}

}```

2. ## Re: Create two dimensional array from a one dimensional array

Is this the same problem: File reading issues