# [Java]: Square Pasture (1st Problem) Debugging Help

Square Pasture (Bronze)

Java

`````` import java.util.*;
import java.io.*;

public class SquarePasture {

public static void main(String[] args) throws IOException {

Kattio io = new Kattio("square");
int x1 = io.nextInt(), y1 = io.nextInt(), x2 = io.nextInt(), y2 = io.nextInt();
int x3 = io.nextInt(), y3 = io.nextInt(), x4 = io.nextInt(), y4 = io.nextInt();
//find the sides of the smallest rectangle covering both pastures
int left = Math.min(x1, x3);
int right = Math.max(x2, x4);

int bottom = Math.min(y1, y3);
int top = Math.max(y2, y4);

int side = Math.max(right - left, top - bottom);

io.print(side * side);
io.close();

}

static class Kattio extends PrintWriter {
private StringTokenizer st;

// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
}

// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
return st.nextToken();
} catch (Exception e) { }
return null;
}

public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}

}
``````

When I tried getting it graded, it gives me an error of:

Exception in thread â€śmainâ€ť java.io.FileNotFoundException: square.in (The system cannot find the file specified)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:211)
at java.base/java.io.FileInputStream.(FileInputStream.java:153)
at java.base/java.io.FileInputStream.(FileInputStream.java:108)
at usaco.SquarePasture\$Kattio.(SquarePasture.java:47)
at usaco.SquarePasture.main(SquarePasture.java:17)

## Checklist

• Include a link to the problem
• Format your post (especially code blocks)
• Include what youâ€™ve tried so far
1 Like

I just submitted this and it passed â€¦ (have you tried resubmitting it? maybe USACO died temporarily or smth)

Btw your code is not properly formatted.

(especially language-specific code blocks such as the following).

Hello Benq,
Thanks for your reply. When I submit it, it gives me 10 exclamation marks in red boxes. When I click on my submission details, it gives me a â€śRTEâ€ť which Iâ€™m assuming means Runtime Error.

Kattio io = new Kattio(â€śsquareâ€ť);

I think that this is the reason why it is marked wrong.

Can you share a screenshot of the result? Iâ€™m pretty sure there no way to see 10 exclamation marks â€¦ you need to at least pass the sample to see your result for the other cases.

Yes. One moment

You should have mentioned that you are not submitting directly through the USACO website. Did you try changing that line to

``````Kattio io = new Kattio();
``````

so that it uses standard input/output instead of file input/output?

Oh. I didnâ€™t know that you could submit directly to the USACO website. (Could you give me the link to that please ) Yes! It worked tysm!!!

Scroll down to the bottom of the link you sent.

Ok ty I will close this now