Results 1 to 3 of 3
  1. #1
    loosemember is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default Finding line number

    Hi


    im creating a program in java that will read a text file then report the line number of a letter that it detects

    if the line is blank it will ignore it but if the line has the letter it is looking for the program will output the line number

    im not sure how to go about this

    thanks

  2. #2
    RichWade is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    Create an int variable, call it something like "line_count", initialize it to zero.

    Start a loop that will read lines from the text file. Read a line, check if the line is blank, if not blank then increment your variable, "line_count++;".

    Check the characters in the line. If you find the character you are looking for then output the line number (line_count).

    Shouldn't be too hard to do this.

  3. #3
    loosemember is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    thx i got it working

    for (int i=0;i<8;i++)
    for (int j=0;j<8;j++)
    if (bd[i][j]=='p')

Similar Threads

  1. Finding the largest number in an array
    By starchildren3317 in forum New To Java
    Replies: 14
    Last Post: 11-03-2010, 07:49 AM
  2. Finding nth prime number
    By dextr in forum New To Java
    Replies: 2
    Last Post: 04-13-2010, 12:42 AM
  3. Finding a number in array close to another number
    By SteroidalPsycho in forum New To Java
    Replies: 2
    Last Post: 02-15-2010, 01:37 AM
  4. finding length on a number
    By thekrazykid in forum New To Java
    Replies: 8
    Last Post: 12-12-2008, 09:07 PM
  5. Finding the highest number
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 11-04-2008, 09:14 AM

Posting Permissions

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