Home Answers Viewqa Java-Beginners Probblems with printing if my innput of text file is correct..

 
 


Clint Sharp
Probblems with printing if my innput of text file is correct..
0 Answer(s)      a year and a month ago
Posted in : Java Beginners

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 Pages:
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
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
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
XML response correct in broser but incorrect in Java
! My code for getting and printing the response: Example 1: URL url = new URL...XML response correct in broser but incorrect in Java  Firs of all I... is not correct. In browser shows me (correct): <ENELIT> <GESI>
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
printing in java
printing in java  hello i want to print a jInternalframe containing some lebels,but my printer sent me a paper with the following written on it: "www.java2s.com" please what is the problem
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
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
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
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?  my textfile with name list.txt: Rice... in my text file, if the item i entered matches with item in text file.how can i...]; for(int i=0;i File file ; FileReader fr=null ; FileWriter
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
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  
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
how printing landscape?
how printing landscape?  I have code which print some data from data base with "drawString()" and it works correct when I chose "Portrait" from "Print Dialog", but it does not work if chose "Landscape". Is any way to print
printing example - Java Beginners
printing example  Is it possible to print java controls using print method? My problem is to print a student mark list using java? The mark list should like that of university mark list
Photoshop Tutorial : How to make a animated text.
;   Save file: Now save optimize (Ctrl + Alt + S) to animate your text as I... How to make a animated text.       This is an animated example, I have made here a text animation
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
Printing ArrayList - JSP-Servlet
Printing ArrayList   I have a code in servlet like this ArrayList...(request,response); to print the values in ArrayList total, I did this in my JSP... is being printed in my page. please help me if i did anything wrong in the syntax
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
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct...  my project has login in whic i should select the company name...;tr><td>Username:</td><td><input type="text" name="user
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct...  my project has login in which i should select the company name...;table> <tr><td>Username:</td><td><input type="text
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
how to sort the text file and display it in jtable
how to sort the text file and display it in jtable   my text file is: contig00001 length=586 numreads=4 CGGGAAATTATCcGCGCCTTCACCGCCGCCGGTTCCACCGACGAACGGATACTGCGtGaa
Example of printing Text message passed from XML to JSP
Example of printing Text message passed from XML to JSP... are going to know how we can pass a text message from XML to JSP.  ... object from an XML document. For this what we need is a XML file in which we have
Count characters from text file in Java
Count characters from text file in Java  At the "Count chracters fro... the directory of the text file ("C:\text.txt"). I use Eclipse to run this code. I copied the text.txt into the same folder of src of the file, and put my directory
Text File I/O - DVD.java - Java Beginners
Text File I/O - DVD.java  NEED HELP PLEASE. The application should use a text file with one value on each line of the file. Each movie would use... the array to recreate the file. Here is my code but I need to modify
iPhone Text Field Validation
iPhone Text Field Validation In any user based application "validations" plays a very important role in order to get unique and correct data from user. In this tutorial we are going to limiting the text field input
Help with opening a text file upon closing a program.
Help with opening a text file upon closing a program.  I need some... that is a swimming pool volume calculator. It stored that data on a output.txt file but I want that file to open whenever the user exits the program. My code so far
JFrame Components Printing - Swing AWT
PrintExample() { super("Printing Swing Components... the print button error sir please i need it for my complteion of my little project
JFrame components printing - Swing AWT
(String[] args) { new PrintExample(); } public PrintExample() { super("Printing... please go through the print button error sir please i need it for my completion of my little project thanking you a lot sir
JFrame components printing - Swing AWT
(String[] args) { new PrintExample(); } public PrintExample() { super("Printing... please go through the print button error sir please i need it for my complteion of my little project thanking you a lot sir
file uploads to my web site
file uploads to my web site  How can I allow file uploads to my web site
Printing the title of a remote page
Printing the title of the remote page In the following example we have...; For this, first define the file name to be printed the title. Open the file. If file would... successful to open, it will print the title of the page.  <?php $file
Read specific column data from text file in java
Read specific column data from text file in java  My question is if my text file contain 15 columns and i want read specific column data from that text file then what code i should do
How to make a golden text,golden text, text effect
are going to tell you here. Design a golden text is not tough now because my this example is base on the golden text so follow my this examples. Take a New File: First take a new black background file as I have here. Write Text
attach file in my web page
attach file in my web page  hide button in input typ=file button in jsp
Designing Printing Motion of a Paper
this image. Text Paper: Take a new file with accurate size of the blank paper... of your text file as you have created up then past in the final image, you... Designing Printing Motion of a Paper. It is very interesting
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  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
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
Handle Null Pointer Exception while text file upload
uploading text file into database if a different text file is selectedi.e...,my db...Handle Null Pointer Exception while text file upload  I want the code for handling null pointer exception in jsp page. That is I need an error page
this is my file upload page, here i am not getting tags input field value to my servlet,please suggest a solution?
this is my file upload page, here i am not getting tags input field value to my...="file" name="file0"/> Tag Here <input id="tag1" type="text" name...; <script type="text/javascript"> var counter =1; function
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
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
How to design a glass text, design a glass text, glass text
are not able to make a glass text effect, come to my this example, it will surely help you..., control the file size as you required. Write Text: Choose Horizontal type tool (T key) and make formatting then write text in the file as given below
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

Ask Questions?

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.