Hello I am beginning to do some questions on dmoj link here: https://dmoj.ca/problem/ccc03j2
I have written the code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x = 0;
int y = 0;
boolean loop = true;
StringBuilder result = new StringBuilder();
while(loop){
int pictures = Integer.parseInt(br.readLine());
if(pictures == 0){
break;
}
int max = (int) Math.ceil(Math.sqrt(pictures));
int min = (int) Math.floor(Math.sqrt(pictures));
if(pictures % max == 0){
x = max;
y = pictures / max;
}
else if(pictures % min == 0){
x = min;
y = pictures / min;
}
int perimeter = ((x+y) / 2) * 4;
if(x < y){
result.append("Minimum perimeter is " + perimeter + " with dimensions " + x + " x " + y);
}else if(y < x){
result.append("Minimum perimeter is " + perimeter + " with dimensions " + y + " x " + x);
}else{
result.append("Minimum perimeter is " + perimeter + " with dimensions " + y + " x " + x);
}
System.out.println(result);
result.setLength(0);
}
}
}
but when it prints to the console it results in this:
100
15
195
0Minimum perimeter is 40 with dimensions 10 x 10 //Why is my output on the same line as my input?
Minimum perimeter is 16 with dimensions 3 x 5
Minimum perimeter is 56 with dimensions 13 x 15
Please help, I am a beginner and im having trouble with the basic input output thanks!