Results 1 to 2 of 2
  1. #1
    TIMBERings is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default I don't understand the output,

    Java Code:
    while(fromFile.hasNextLine()) {			//goto next Node here
    	while(fromFile.hasNext()){ 		//create nested linked list here
    		input=fromFile.next();
    		System.out.print(input + " ");	//Will print everything twice.		
    		try {
    			hold = Integer.parseInt(input);
    			System.out.print(hold + " ");
    			adjMatrix[i][hold-1]=1;
    		}
    		catch (NumberFormatException e) {
    		}
    				
    	}
    	System.out.println();
    	i++;
    }
    Produces this:
    Java Code:
     2 2 
     1 1 
     2 2 4 4 
     3 3 
     2 2 
     2 2 5 5 7 7 
     3 3 6 6 
     4 4 7 7 8 8
    Which makes complete sense, however if this is my code:
    Java Code:
    while(fromFile.hasNextLine()) {			//goto next Node here
    	while(fromFile.hasNext()){ 		//create nested linked list here
    		input=fromFile.next();
    							
    		try {
    			hold = Integer.parseInt(input);
    			System.out.print(hold + " ");
    			adjMatrix[i][hold-1]=1;
    		}
    		catch (NumberFormatException e) {
    		}
    				
    	}
    	System.out.println();
    	i++;
    }
    My results are this:
    Java Code:
    2 1 2 4 3 2 2 5 7 3 6 4 7 8
    What I want is:
    Java Code:
     
    2
    1
    2 4
    3
    2
    2 5 7
    3 6
    4 7 8
    If I remove the try catch statement as well as only print the String, I have no issues, but I need to convert the String to an integer for matrix values.

    Any help would be great, thank you.
    Last edited by TIMBERings; 12-10-2009 at 07:55 AM. Reason: Coding edits

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

Similar Threads

  1. cant understand what this means
    By hasysf in forum New To Java
    Replies: 19
    Last Post: 09-05-2009, 04:27 PM
  2. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  3. I dont understand
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 02-22-2009, 11:22 PM
  4. New: Want to understand Drawing...
    By diRisig in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 08:13 AM
  5. i don understand this error
    By Deon in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 10:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •