+ 1

I have a problem of java code

The code should give me a square or rectangle shape but it doesn't public class Main { public static void main(String[] args) { for(int i=5;i>=1;i--){ System.out.println("#"); for(int j=1;j<=5;j++){ System.out.print("#"); } } } }

14th Jan 2022, 11:07 PM
Tony Jadesola
2 Answers
+ 6
//Practice makes perfect: here you can use basic for loop, //inner loop for a line of characters // and outer loop for go to next line for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ System.out.print("#"); } System.out.println(); }
14th Jan 2022, 11:15 PM
JaScript
JaScript - avatar
+ 4
You can create a method for it so you can call it dynamically, when necessary, passing the shape size as method's argument. private static void drawBox( int size ) { for( int y = 0; y < size; y++ ) { System.out.println( "#".repeat( size ) ); } System.out.println(); } Please tag Java, the language related to the question and the code. https://code.sololearn.com/W3uiji9X28C1/?ref=app
15th Jan 2022, 1:14 AM
Ipang