+ 2
Can somebody helps me out to print the below pattern in java ?
#### # # # # ####
6 odpowiedzi
+ 3
Yes many can and will if you show us an attempt of yours and why are you posting other's codes with the question? Since you have access to CEO's post please read the rules for tags etc.
+ 3
that pattern will need 2 for-loops (-> one inside the other)
this would be half the solution, try to finish it so you can improve 😁:
int width = 4;
int height = 4;
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
if(i == 0 || j == 0){
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.print("\n"); //new Line
}
+ 1
Type 3 and then 0 in the following code, you will get a similar output...
https://code.sololearn.com/cTWPt2sX6W8Y/?ref=app
Only replace 1 with #...
+ 1
mn121 isn't that quite a lot of code for such a simple pattern... 😅😅
int width = 4;
int height = 4;
for(int i=0;i<height;i++){
for(var j=0;j<width;j++){
if(i == 0 || j == 0 || i == height-1 || j == width-1){
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.print("\n");
}
+ 1
Anton Böhler I asked to check case 3 only not the whole program😁😁😁...
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
if(j==1||j==4||i==1||i==4)
System.out.print("#");
else
System.out.print(" ");
}
System.out.println();
}
+ 1
mn121 got carried away 😂😂😂