Print -----1 ----2 ---3 --4 -5 | Sololearn: Learn to code for FREE!

+2

Print -----1 ----2 ---3 --4 -5

Blank space programs Java language https://code.sololearn.com/cUGBWkiOrP48/?ref=app https://code.sololearn.com/c74tW9E81yUP/?ref=app

11/25/2021 1:19:07 PM

Sukhneek Kaur

12 Answers

New Answer

+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

+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

+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 ); } } }

+2

https://code.sololearn.com/c3TpUyE1Hd0a/#c Try This And Upwote

+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 ...

+1

If you want them all to print in a single line, then replace println with print

+1

Thank you everyone for being so kinf

+1

I’ve learnd print python is cool today ^ ^

0

First dashes then number

0

First print "-" Then print next thing 👍 I wish it will be clear

0

Thanks for giving new program.

0

Hi