I don't know why I write wrong code :(
it requires to draw an n x m rectangle of eight.
i write a code (drawLine) to draw top and bot of rectangle.
i write a code (drawSpace) to draw left and right of rectangle.
and a code (rectangle) to draw completely rectangle.
My code run ok. i try 2x4 , 3x5 , 9x9 it show correct nxm of rectangle
but "The program should display a n x m rectangle made of eights." still show is not correct ?
sorry, I'm not good English.
package com.codegym.task.task04.task0436;
/*
Drawing a rectangle
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bufferedReader.readLine());
int m = Integer.parseInt(bufferedReader.readLine());
rectangle(m,n);
}
private static void drawSpace(int a){ //i draw [8 8]
for(int i=1;i<=a;i++) {
if(i==1 || i==a) System.out.print("8");
else System.out.print(" ");
}System.out.println("");
}
private static void drawLine(int a){ //i draw [88888888]
for(int i=1;i<=a;i++) System.out.print("8");
System.out.println("");
}
private static void rectangle(int a,int b){ //88888 i draw like it
for(int i=1;i<=b;i++) //8 8 m = 4, n=5
{ //8 8
if(i==1||i==b) drawLine(a); //88888
else drawSpace(a);
}
}
}