Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: can someone help me debug plzz

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can someone help me debug plzz

    so i got this code....which should read and store 300 lines.....but it's not starting from the beginning of the text....its starting from the 2nd and sometimes the 5th line................someone help me debug
    import java.util.Scanner;
    import java.io.File;
     
    class copyofcode
    {
     
    	public static void main (String args[])throws Exception
    	{
     
    		String[]text=new String[300];
     
    		File myfile = new File("alice.txt");
    		Scanner scan = new Scanner(myfile);
     
     
     
     
            /* reading 20 lines and storing them and printing them out to the screen*/
     
    		for (int a=0; a<300; a++)
    		{
    			   text[a] = scan.nextLine();
    			   if(text[a]==null)
    			   break;
    			   System.out.println(text[a]);
    		 }
     
    		scan.close();   //closing the file
     
       }
    }
    Last edited by copeg; November 27th, 2010 at 11:12 AM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: can someone help me debug plzz

    Tried it out on my a text file containing:

    "The King and Queen of Hearts were seated on their throne when they arrived,
    with a great crowd assembled about them--all sorts of little birds and beasts,
    as well as the whole pack of cards: the Knave was standing before them, in
    chains, with a soldier on each side to guard him; and near the King was the
    White Rabbit, with a trumpet in one hand, and a scroll of parchment in the
    other. In the very middle of the court was a table, with a large dish of tarts
    upon it: they looked so good, that it made Alice quite hungry to look at them--
    `I wish they'd get the trial done,' she thought, `and hand round the
    refreshments!'

    But there seemed to be no chance of this, so she began looking at everything
    about her, to pass away the time. "

    And it worked fine with an added try catch, but worked fine without it just gave exception warning in the middle.

Similar Threads

  1. can' stop working a part of code.plzz help
    By kyros in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 30th, 2010, 03:10 PM
  2. plz help me with this.....plzz....
    By renny in forum Java Theory & Questions
    Replies: 25
    Last Post: May 18th, 2010, 08:19 AM
  3. Works on debug mode but not on run mode
    By alfonsoraul in forum Member Introductions
    Replies: 0
    Last Post: April 14th, 2010, 02:58 PM