+ 2
How do I print numbers like this: 1 21 321 in the shape of a pyramid
5 Réponses
+ 3
I think like this you want on java
public class Program
{
public static void main(String[] args) {
String sum = "";
for(int i = 1; i < 10; i++){
for(int j = i; j > 0; j--){
sum += j+"";
System.out.print(j);
}
System.out.println();
}
}
}
or one loop
public class Program
{
public static void main(String[] args) {
String sum = "";
for(int i = 1; i <= 10; i++){
sum += i+"";
System.out.println(sum);
}
}
}
+ 3
oh the question was for java ... sorry Ferhats code looks good although there is one for loop to much
+ 2
nums=""
for i in range(1,10):
nums += str(i)
print(nums)
this should work... i am sure there is a even shorter or better way but you get the idea
edit: i changed 100 to 10 because sololearn has a time limit
+ 2
Yes, Python is very easy for loop, you are done with one line or two lines