Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Clint Sharp
Probblems with printing if my innput of text file is correct..
0 Answer(s)      2 years and 5 months 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) {

    }


}

Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
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  
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
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
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
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
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
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
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
Advertisements
 

 

 

DMCA.com