0
Write a program to give output as a ?
12345 *2345 **345 ***45 ****5
3 Réponses
+ 6
Java:
public class Program
{
public static void main(String[] args) {
for(int i = 1; i < 6; ++i) {
int j = 1;
for(; j < i; ++j) {
System.out.print("*");
}
for(; j < 6; ++j) {
System.out.print(j);
}
System.out.println();
}
}
}
Python:
for i in range(1, 6):
for j in range(i-1):
print("*", end="")
for k in range(6-i):
print(k+i, end="")
print()
Not very elegant, but hopefully easy to understand.
+ 3
Less easy to understand than @ChaoticDawg's, added just for thinking:
maxx = 5
stars = "*" * maxx
nums = "".join( [str(c+1) for c in range(maxx)] )
for n in range(maxx):
print(stars[:n] + nums[n:])
0
heres a one line in python...
https://code.sololearn.com/cl2wculIAqyT/?ref=app