Star and numbers pattern | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Star and numbers pattern

Can anyone help me how to code in java a pattern like this one given n = 5 ? *234 **34 ***4 ****

6th Nov 2018, 2:42 PM
Roberto
10 Answers
+ 3
Roberto Where is your try??
6th Nov 2018, 2:55 PM
KrOW
KrOW - avatar
+ 3
Roberto You can use a classic loop where at any iteration "i", you print: - I+1 times "*" - sequence of int starting from i+1 to n
6th Nov 2018, 3:21 PM
KrOW
KrOW - avatar
+ 2
Roberto Post anyway because its a proof that you dont ask for easy solution (eg. other make your assignement for you)... Sorry, but here there are many requests like that type
6th Nov 2018, 2:59 PM
KrOW
KrOW - avatar
+ 1
Thanks I'll try the i+1 times "*" suggestion and see...
6th Nov 2018, 3:36 PM
Roberto
+ 1
Roberto Please, when you post some code, its helpful to who help you, if you save it in Code Playground section and post his link in comment... For now i made it for you but next time, please, do yourself...Anyway, this is your code which i have added some comments hints https://code.sololearn.com/cFep9ZIIG9p2/?ref=app
6th Nov 2018, 8:15 PM
KrOW
KrOW - avatar
6th Nov 2018, 8:32 PM
Roberto
+ 1
Roberto Nice work 👍👍👍
6th Nov 2018, 9:24 PM
KrOW
KrOW - avatar
0
There is not... to difficult for me, I tried but the result is not the one expected
6th Nov 2018, 2:56 PM
Roberto
0
Sorry actually for the given example n should be equal to 4
6th Nov 2018, 3:04 PM
Roberto
0
I tried this code below, which of course is wrong, but I can't figure out how to print the desidered pattern: public class Main { public static void main(String[] args) { int n = 5; int i, j; for (i = 1; i < n+1; i++) { String row = ""; for (j = 1; j < n+1; j++) { if (i == j) { row += "* "; System.out.print(row + "\n"); } else { System.out.print(j); } } } } } * 23451* 34512* 45123* 51234*
6th Nov 2018, 7:31 PM
Roberto