+ 1

how to print a series like this using loops 54321 4321 321 21 1

1st Nov 2016, 12:43 PM
SARTHAK AGARWAL
7 Antworten
+ 1
What should your input be? For a String input, a possible method could be: public static void yourMethod (String input) { for (int i = 0; i < input.length(); i++) { System.out.println (input.substring(i, input.length())); } }
1st Nov 2016, 1:42 PM
merkrafter
+ 7
you can use two for loop to do this, here is my code public class Program { public static void main(String[] args) { int i,n; for(i=5;i>0;i--){ for(n=i;n>0;n--) { System.out.print(n); } System.out.print("\n"); } } }
3rd Nov 2016, 3:10 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
Your input in this case is a string. A string is like an array of characters. In this example, the string would be "54321". The for loop iterates over i=0...4 (the input length is 5). In the first iteration (i = 0) it prints out the indices 0 to the end from your character array. These are "54321". In the next iteration (i=1) it prints out the characters from the indices 1 to the end, so "4321" and so on.
1st Nov 2016, 5:29 PM
merkrafter
0
you can use nested loop to that
1st Nov 2016, 7:55 PM
sami hamza
sami hamza - avatar
0
👍
2nd Nov 2016, 10:37 AM
SARTHAK AGARWAL
0
you means me
3rd Nov 2016, 11:18 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
- 1
please elaborate
1st Nov 2016, 4:46 PM
SARTHAK AGARWAL