- 1
23rd May 2022, 12:24 PM
Ranjna Gupta
5 Answers
+ 1
for(int s=1;s<=5;s++) { for( int d=1;d<=s;d++) { System.out.print(d); // print d and use print method, variable d is local to this loop only. outside it not exist. } System.out.println(); // use println here } // now try to reverse it... // print from 5 to 1 instead of 1 to 5 by decrementing each iteration. use d=s; d>0;
23rd May 2022, 12:39 PM
Jayakrishna 🇼🇳
+ 1
Ranjna Gupta Start first loop from 5 till > 0 in reverse order. Print d inside 2nd loop and empty line outside 2nd loop. You have just printed opposite means first empty line then d. See the scope of variable d, it is inside for loop not outside.
23rd May 2022, 2:08 PM
AÍąJ
AÍąJ - avatar
0
Read about nested loops.. Then try yourself first and post your attempt if not successful...
23rd May 2022, 12:28 PM
Jayakrishna 🇼🇳
0
What is a "prymaid"? Have a look at the Java course to revise the basics: https://www.sololearn.com/Course/Java/?ref=app
23rd May 2022, 12:35 PM
Lisa
Lisa - avatar
0
Review variables scope. Specifically, variable "d": which is its scope, and where you're trying to access it. Also, review string output - with and without line breaks.
23rd May 2022, 1:00 PM
Emerson Prado
Emerson Prado - avatar