Results 1 to 2 of 2
  1. #1
    Dex
    Dex is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Default First time Scanner Help

    Hey guys this is my first time using scanners and I was wondering how you would scan something from a text file that is within a nested for loop.
    e.g:

    Java Code:
    for (int i=0; i <ROWS; i++) {
            for (int j=0; j < COLS; j++) {
              if (twoDArray[i][j] == null) {
                pW.println("null");  // how would i scan this line 
              } else {
                pW.println(cards[i][j].getCardStatusInformation()); // and this line
              }
            }
          }
    I think I already understand some of the basics of scanning, e.g

    Java Code:
    pW = new PrintWriter(fileName);
          pW.println(WidthOfWall);
    could be scanned by:

    Java Code:
     scan = new Scanner(fileName);
        WidthOfWall = scan.nextInt();
    I hope this made sense, thanks.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: First time Scanner Help

    Quote Originally Posted by Dex View Post
    I hope this made sense, thanks.
    Scanner is used for reading data in. PrintWriter is for writing data out. So, no your post doesn't make sense. Btw, using a Scanner inside a nested for loop is exactly the same as using a Scanner inside a single loop or no loop at all for that matter.

Similar Threads

  1. Replies: 5
    Last Post: 02-29-2012, 11:07 AM
  2. is there any way to handle ideal time session time out
    By javastuden in forum Java Servlet
    Replies: 0
    Last Post: 02-03-2012, 12:02 PM
  3. Replies: 3
    Last Post: 12-07-2011, 08:00 AM
  4. Replies: 3
    Last Post: 08-23-2011, 01:46 PM
  5. calculate time diff for particular time period
    By baktha.thalapathy in forum New To Java
    Replies: 2
    Last Post: 05-24-2010, 05:10 PM

Posting Permissions

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