Probblems with printing if my innput of text file is correct..

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









Related Tutorials/Questions & Answers:
Probblems with printing if my innput of text file is correct..
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
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
Advertisements
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
Printing numbers up to N into a file
Printing numbers up to N into a file  I'd like to print the first N integers, that is, "1, 2, 3, 4, ..., N-1, N", say N equals 1000, or 10000 or whatever. I'd also like to have the result stored as a file instead of having
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
plz check my codings are correct or not...There is an error..i cant find it..
plz check my codings are correct or not...There is an error..i cant find it..  import java.util.Scanner; public class Student { private String...() { Scanner text= new Scanner(System.in); Scanner num=new
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
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
how to update the text file?
how to update the text file?  if my text file contains a string... the integer value if my input String matches with the string in file. please help me in developing this code which is part of my project
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
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... i want to update the quantity in my text file, if the item i entered matches...=new float[n1]; for(int i=0;i File file ; FileReader fr=null
df in linux not showing correct free space after file removal
df in linux not showing correct free space after file removal  Hi, I have deleted a big file in linux but df is not showing correct free space after... is not showing the file. How to resove this issue? df in linux not showing correct
Produces XML file but format not correct for storing data using JSP and XML
Produces XML file but format not correct for storing data using JSP... entered by user in XML file ,It stores data entered in XML file... is entered in XML file. XML file created : <?xml version = '1.0' encoding
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
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
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
file uploads to my web site
file uploads to my web site  How can I allow file uploads to my web site
attach file in my web page
attach file in my web page  hide button in input typ=file button in jsp
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
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
how to convert image file to text file?
how to convert image file to text file?  hi, can anybody tell how to convert image file to text file? plz help me
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
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
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
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
Creating a log in a text file - Applet
as an application. Therefore i have added it onto a frame. I need to create a text file... time it is run. I have figured of a way of writing the time to a text file using..."); Label label1 = new Label("Enter the file name:"); TextField text = new
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.ADS
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
ModuleNotFoundError: No module named 'text-file-reader'
ModuleNotFoundError: No module named 'text-file-reader'  Hi, My... named 'text-file-reader' How to remove the ModuleNotFoundError: No module named 'text-file-reader' error? Thanks   Hi, In your
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
how to match the key word from a text file
how to match the key word from a text file  p>Hi all, I have the code to match the key word and from the text. I have input like this reader.txt... ((devstr = br.readLine()) != null) { String text = devstr; String text1
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me   Hi have develop the jsp to populate related birds whenever we give input in the text field. But i am getting the wrong
How to append text to an existing file in Java
How to append text to an existing file in Java  How to append text to an existing file in Java
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
Java search text file
Java search text file In this tutorial, you will learn how to search a text file in the current directory. For this, we have prompt the user to enter the name of a text file to search for. If the name does not have a .txt extension
how to send my system.out.println in a class file to a jsp in Struts2
how to send my system.out.println in a class file to a jsp in Struts2   System.out.println("File" + f + " contains text " + text + " at line " + hm1.keySet() + " and index "+ hm1.values() ); I want
why my downloaded file is alwayes damaged or corrupted?
why my downloaded file is alwayes damaged or corrupted?  This is my... (($file = $dirPath->read()) !== false) { if ((substr($file, -3)=="gif") || (substr($file, -3)=="jpg") || (substr($file, -3)=="png
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes

Ads