Printing lines from a text file in reverse order

前端 未结 2 699
眼角桃花
眼角桃花 2021-01-26 01:34

I am trying to read in the Constitution as a text file from the command line into my program to print out the lines in reverse order. My for loop looks like this:



        
相关标签:
2条回答
  • 2021-01-26 02:04

    Make int i equal the number of lines in the Constitution instead of 0 that should do it.

    0 讨论(0)
  • 2021-01-26 02:16

    When you reverse a loop's iteration direction, you also have to reverse the beginning and ending values.

    for(int i = arrayCount-1; i >= 0; i--)
    

    Now, this loop starts at the end, then works back down to the beginning of the array.

    0 讨论(0)
提交回复
热议问题