25th Nov 2021, 1:19 PM
Sukhneek Kaur
12 ответов
+ 2
public class Program { public static void main(String[] args) { int i,j; for(i=1;i<=5;i++) { for(j=5;j>=i;j--) System.out.print("-"); System.out.println(i+" "); } } } Try this
25th Nov 2021, 1:25 PM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
+ 4
Bro we can edit our responses here, just tap the menu on the right of the response, and choose Edit ... And for future reference, please use appropriate tags https://code.sololearn.com/W3uiji9X28C1/?ref=app
25th Nov 2021, 1:36 PM
Ipang
+ 3
You can use String::repeat() method to replicate a string rather than appending it multiple times. public class DashesAndNumbers { public static void main(String[] args) { String dash = "-"; int lines = 5; for( int i = 1; i <= lines; i++ ) { System.out.println( dash.repeat( i ) + i ); } for( int i = 1, j = lines; i <= lines; i++, j-- ) { System.out.println( dash.repeat( j ) + i ); } } }
25th Nov 2021, 1:32 PM
Ipang
26th Nov 2021, 10:00 AM
Chirag Vasani
+ 1
Should the dashes come before or after the number? your code shows the number followed by the dashes, but your question shows the dashes followed by the number ...
25th Nov 2021, 1:23 PM
Ipang
+ 1
If you want them all to print in a single line, then replace println with print
25th Nov 2021, 1:25 PM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
+ 1
Thank you everyone for being so kinf
25th Nov 2021, 1:34 PM
Sukhneek Kaur
+ 1
I’ve learnd print python is cool today ^ ^
27th Nov 2021, 2:04 AM
X Owo
0
First dashes then number
25th Nov 2021, 1:24 PM
Sukhneek Kaur
0
First print "-" Then print next thing 👍 I wish it will be clear
25th Nov 2021, 2:06 PM
Maneek Kaur
0
Thanks for giving new program.
26th Nov 2021, 10:06 AM
Maneek Kaur
0
Hi
27th Nov 2021, 2:02 AM
X Owo