Probblems with printing if my innput of text file is correct..
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) {
}
}
View Answers
Ads
Related Tutorials/Questions & Answers:
Advertisements
text file
text file Hello can I modify the program below so that all the numerical data is stored in an external
text file,that is the data contained in the array list.Thank you!
mport java.util.*;
import java.text.*;
import
text file
text file Hi can you help me I have to modify the program below so that all the data held in it is stored in an external
text file.So there should... at the start of the program from a seperate external
text file.Thank you!
mport
Sorting text file
Sorting
text file Hello friends, i'm writing search page for
my local website. i'm storing all
file list in
text file. And also adding a value... according to begin value.
Text File having list like this:
5|
3|
can anyone
Convert Text File to PDF file
Convert
Text File to PDF file Here is the way how to covert your
Text file to PDF
File,
public class TextFileToPDF {
private static void...(inLine);
System.out.println("
Text is inserted into pdf
file
Reading a text file in java
Reading a
text file in java What is the code for Reading a
text file... in java.io.* package for reading and writing to a
file in Java.
To learn more about reading
text file in Java see the tutorial Read
File in Java.
Thanks
Convert Text File to PDF file
Convert
Text File to PDF file import java.io.BufferedReader;
import...);
System.out.println("
Text is inserted into pdf
file");
document.close... FileReader(
Input
File));
String inLine = null
Text field save as word file
Text field save as word file Dear experts At run how to save set of
text field contains
text into single Word
file. To save in our desktop computer. Solve
my problem
uploading a text file into a database
uploading a
text file into a database how to upload a
text file... {
static
File file;
public static void main(String[] args) throws Exception {
JLabel label=new JLabel("Choose
File
writing a text into text file at particular line number
writing a
text into
text file at particular line number Hi,
thanks for quick response, I want to insert
text at some particular line number..
after line number four
my text will display in
text file using java program
 
writing a text into text file at particular line number
writing a
text into
text file at particular line number Hi,
thanks for quick response, I want to insert
text at some particular line number..
after line number four
my text will display in
text file using java program
 
Read text File
Read
text File Hi,How can I get line and keep in a String in Java
Read Lines from text file
Read Lines from
text file Here's a brief desc of what
my Java code... line based on a predefined size...
Eg : If the 1st line of the
text file... need to do this for a
file with 11 lines.
Here's
my code
while((line
Converting Text Files into Bzip File
Converting
Text Files into Bzip File Hi,
I am facing the problem during run the program, when converting
text files into Bzip
file. Please guide me how do i convert the
text file into bzip
file in PHP. I will welcome, if anyone
Reading Text file and storing in map
Reading
Text file and storing in map Hi
I have multiple
text files. I want to read thoses files and store those records in map.
Map will be of "LinkedHashMap<String, Map<String, String>>" type.
Please let me know
regarding css file in my eclipse
regarding css
file in
my eclipse hai frns
i want a small help frm u.when ever i use css
file in html or normal web browsers the output is coming means css
file is effecting the output but wen i use the same code in myeclipse
Steps to read text file in pyspark
Steps to read
text file in pyspark Hi,
I am learning to write program in PySpark. I want to simply read a
text file in Pyspark and then try some code.
What are the Steps to read
text file in pyspark?
How much time it takes
a jsp code for creating a text file
a jsp code for creating a
text file Hello,i need jsp code for creating a new
text file for each user, when they login in to the website for creating a new data
file.
So i need a jsp code for following options.
when user login
Write Text into File
Write
Text into
File
In this example we are writing
text
into file.In...
to write
text into
file. At last close output
file using close()
method
JavaScript write to text file
JavaScript write to
text file
 ... are going to create a
file and write
text into it
using JavaScript.
In the given example... to write the
text into the created
file, we have used
WriteLine() method. This code
Search and return lines of text file
Search and return lines of
text file I wrote the following code, that found lines of txt
file with contains certain word, but it returns only the first or the last line! (However, the System.out.println show me all the lines