
I am trying to make sure this block of code does what I think it will do. Can someone show me with some code how I can print out what is is labled with <----print this? There are 3 of them. I am looking for something rather simple and for some reason I cannot get the code to work with System.out.println().
Blockquote
import java.io.*; import java.util.*;
class CitiesDist { //<---print this
String cityOne;
String cityTwo;
int miles;
}
class City { // <---print this
String cityName;
int numberLinks;
CitiesDist[] citiesDists;
}
public class P3 {
City[] cities;
void initCity(int len) {
for (int i = 0; i < len; i++) {
cities[i] = new City();
}
}
void initCitiesDist (int index, int len) {
for (int i = 0; i < len; i++) {
cities[index].citiesDists[i] = new CitiesDist();
}
}
void parseFile() throws FileNotFoundException, IOException {
FileInputStream fstream = new FileInputStream("Data.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int numberCities = Integer.parseInt(br.readLine());
cities = new City[numberCities];
initCity(numberCities);
for (int i = 0; i < numberCities; i++) {
String line = br.readLine();
int numberLink = Integer.parseInt(line.split(" ")[1]); // <--- print this
cities[i].cityName = line.split(" ")[0];
cities[i].numberLinks = numberLink;
initCitiesDist (i, numberLink);
for (int j = 0; j < numberLink; j++){
line = br.readLine();
cities[i].citiesDists[j].cityOne = line.split(" ")[0];
cities[i].citiesDists[j].cityTwo = line.split(" ")[1];
cities[i].citiesDists[j].miles = Integer.parseInt(line.split(" ")[2]);
}
}
}
public static void main(String[] args) {
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.