- 1
How to make prymaid
54321 5432 543 54 5 https://code.sololearn.com/cm109KF44TZe/?ref=app
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;
+ 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.
0
Read about nested loops.. Then try yourself first and post your attempt if not successful...
0
What is a "prymaid"?
Have a look at the Java course to revise the basics:
https://www.sololearn.com/Course/Java/?ref=app
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.