English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

here is the output

12345
1234
123
12
1

need the syntax for this using "for loop" please help anyone...

2007-08-29 23:32:47 · 5 answers · asked by a_stupid_java_programmer 1 in Computers & Internet Programming & Design

5 answers

Your first two respondents used the wrong loop syntax (the second expression is "as long as", not "until"), so for example:

for (x=5; x=0; --x)

... will not run even once, because the first time through the loop x does not equal zero.

The remainder used ">" when they wanted ">=" ('as long as x>=1'), so their loop would stop with the '12' line and exit when x reached 1.

for (int x=5; x>=1; x--) {
for (int y=1; y<=x; y++) {
System.out.print (y);
}
System.out.println();
}

2007-08-30 03:08:51 · answer #1 · answered by McFate 7 · 1 0

class trial
{
public static void main(String args[])
{
int x =5 ; int y=1;
for (x=5; x>1; x--)
{
for (y=1; y<=x; y++)
{
System.out.print (y);
}
System.out.println();
}
}
}

2015-03-09 23:38:37 · answer #2 · answered by Rohit 1 · 0 0

class trial
{
public static void main(String args[])
{
for (x=5; x>1; x--)
{
for (y=1; y<=x; y++)
{
System.out.print (y);
}
System.out.println();
}
}

2007-08-30 01:20:37 · answer #3 · answered by Suvidha A 3 · 0 0

for (int x=5; x>1; x--)
{
for (int y=1; y<=x; y++)
{
System.out.print (y);
}
System.out.println();
}

2007-08-30 01:38:26 · answer #4 · answered by Sheqi Nonda 3 · 0 0

for( i=5; i=0; i--)
{
...
...
}

2007-08-29 23:38:22 · answer #5 · answered by mayank_bsr 2 · 0 0

fedest.com, questions and answers