+ 1

How to display a certain number of lines while using loops?

How to display a certain number of lines using a for loop. if for instance the output gives 5 lines of integers and with an input value i can decide of how many line i want to display...like two lines intead of 5. Even though is just a part of the content that is being displayed

1st Nov 2016, 8:37 AM
TheDon_P
TheDon_P - avatar
6 Respuestas
+ 5
Hi TheDon_P.. sorry to use your post to get in contact with you, but this app still needs a way of sending private message... Anyway, I saw your code and found two bugs. This is the fixed code: http://www.sololearn.com/app/sololearn/playground/cBiSb1s3Q4sQ/ The first problen was on the condition of the for loop in the reverseArray method.. it should iterate until the index goes less than zero. The second problem that arised was that reverseArray didn't have to return anything, or at least doesn't need to return a element of the array already printed on the screen. S, I change the return type to void and remove and removed the return statatement. You could also leave the int return type but then you should return 0; Hope it helps and sorry to change the topic of your post.
1st Nov 2016, 12:33 PM
Nelson Urbina
Nelson Urbina - avatar
+ 3
int maxLines = 2; for (int i=0; i<Math.min(maxLines, lines.length); i++) { System.out.println(lines[i]); }
1st Nov 2016, 10:27 AM
Tamás Barta
Tamás Barta - avatar
+ 3
Hi, it won't compile as "lines" isn't declared. Let it be: String[] lines = new String[] {"a", "b", "c", "d", "e"};
1st Nov 2016, 1:28 PM
Tamás Barta
Tamás Barta - avatar
+ 1
Hi Nelson, thanks for the correction really appreciated and it helped alot...don't mimd the topic of the post...may the code be with you
1st Nov 2016, 1:13 PM
TheDon_P
TheDon_P - avatar
0
Hi Barta thanks for the reply, but it showing some error
1st Nov 2016, 1:24 PM
TheDon_P
TheDon_P - avatar
0
it worked thanks a lot Barta
1st Nov 2016, 1:47 PM
TheDon_P
TheDon_P - avatar