Hi everyone,
I'm not sure I understand this exercise correctly. I understood the instructions as "make a rectangle with 8 as Strings with as many 8 as the total of number n multiplied by number m".
So I cut the total in half and make a rectangle. With odd numbers I'm not sure what to do but if I have 9 times "8" as a character I can't get a rectangle so I cut one number short.
My solution visually looks correct but I don't think I'm right and it's not accepted.
package fr.codegym.task.task04.task0436;
/*
Dessin d'un rectangle
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int m = Integer.parseInt(r.readLine());
int n = Integer.parseInt(r.readLine());
int half = (n*m/2)-1;
int remainder = n*m%2;
if (remainder==0) {
for (int i=0; i < n*m; i++) {
if(i != half)
System.out.print("8");
else if(i == half)
System.out.println("8");
}
}
else {
for (int i=0; i < n*m-1; i++) {
if(i != half)
System.out.print("8");
else if(i == half)
System.out.println("8");
}
}
}
}