Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.
OK, I know it's not a place for programmers to hag out, but still I thought let's just try...
I am trying to write a simple program in java, which shows output just like this:
0.........30
0........34
0.......33
.
.
.
.
.
upto 0
Now the limit is any number. I supposed 30 here. It's easy with nested loops, but how can I do this with a single for loop? Please you can give answer in any language C++ or java.
2012-10-18 12:01:59
HI the following code will help you n=31;for(i=0;i<n;i++){ if(n==0){ i=n+1; } else if(i==n){ cout<<i<<'\n'; n--; i=-1; } else{ cout<<i<<" "; }}
2012-10-19 08:47:02
ya this will useful !!!!
2012-10-18 12:01:23
n=31for(i=0;i<n;i++){ if(n==0){ i=n+1; } else if(i==n){ cout<<i<<'\n'; n--; i=-1; } else{ cout<<i<<" "; }}it will do
2012-10-18 10:04:05
from what i understand you want to use "for" loop.. But i dont understand what output you want from it... it would be something like.for(int i; i< input.length; i++)printf ("%i",i);