+ 1
how to print a series like this using loops 54321 4321 321 21 1
7 Réponses
+ 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()));
}
}
+ 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");
}
}
}
+ 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.
0
you can use nested loop to that
0
👍
0
you means me
- 1
please elaborate