# Thread: I Need Help!

1. Member
Join Date
Apr 2014
Posts
3
Rep Power
0

## I Need Help!

Can someone tell me what's wrong with this program?
The program should find the biggest corner, based on the number zero.
A zero becomes a corner when there's the same amount of zeros under it, and left to it.
The program should print a message saying what's the biggest corner size.
Corner size is the number of zeros inside it.

Java Code:
```import java.util.*;
class Corners
{
static Scanner reader=new Scanner(System.in);
static final int N=25;
static int corners(int a, int b, int[][] m)
{
int plus=1, minus=1, counterDown=0, counterLeft=0, counter=0;
boolean answer=false, work=true;
if(m[a][b]==0)
{
if(m[a+1][b]==0 || a<N-1)
{
if(m[a][b-1]==0 || b>0)
{
while(work=true)
{
if(m[a+plus][b]==0 || plus<N)
{
counterDown++;
plus++;
}
if(m[a][b-minus]==0)
{
counterLeft++;
minus++;
}
if(m[a][b-minus]==1 || m[a+plus][b]==1 || b>0)
work=false;
}
if(counterLeft==counterDown)
{
counter=counterDown*2+1;
return counter;
}
else
{
for(int i=counterDown ; i>1 ; i--)
{
if(counterLeft==i)
{
counter=i*2+1;
return counter;
}
}
for(int i=counterLeft ; i>1 ; i--)
{
if(counterDown==i)
{
counter=i*2+1;
return counter;
}
}
}
}
}
}
return counter;
}
public static void main(String[]args)
{
int num, max=0;
int[][] theBOX = new int[N][N];
for(int i=0; i<N ; i++)
{
for(int j=0; j<N ; j++)
{
theBOX[i][j]=(int)(Math.random()*2);
}
}
System.out.println();
System.out.println("The BOX:");
for(int i=0; i<N ; i++)
{
for(int j=0; j<N ; j++)
{
System.out.print(theBOX[i][j]+"  ");
}
System.out.println();
}
for(int i=1; i<N ; i++)
{
for(int j=0; j<N ; j++)
{
num=corners(i,j,theBOX);
if(num>max)
max=num;
}
}
System.out.println("The biggest corner has "+max+" zeroes in it!");
}
}```
That's the output:

Java Code:
```The BOX:
1  0  0  1  1  1  0  1  0  1  0  0  1  0  0  0  1  0  0  0  0  0  1  1  1
1  0  1  0  1  0  0  1  0  0  0  1  0  1  1  1  0  1  0  0  0  1  1  1  0
0  1  1  1  1  1  0  0  0  0  0  0  0  1  1  0  0  1  1  0  0  1  0  0  0
0  1  0  1  0  1  1  1  1  1  1  0  0  0  1  1  0  0  1  1  0  1  0  0  1
0  0  1  1  0  0  0  0  0  1  0  0  0  0  1  0  0  1  0  0  0  0  1  1  0
0  0  1  0  1  0  1  0  1  1  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0
1  0  0  0  0  1  1  1  0  1  0  0  0  1  1  0  1  0  0  1  1  0  1  1  1
0  1  0  1  1  0  1  1  0  0  1  1  0  1  0  0  0  0  1  0  1  0  1  0  0
0  1  0  0  0  0  1  0  0  1  1  1  0  1  1  1  1  1  0  0  1  1  1  1  0
0  0  0  0  0  1  0  1  1  0  0  1  1  0  1  0  1  0  0  0  0  1  0  1  0
1  0  0  1  1  1  0  0  0  0  0  0  0  1  1  1  0  0  0  0  1  1  1  0  1
1  1  0  1  1  1  0  0  0  1  1  0  1  0  0  1  0  0  1  0  1  0  0  1  1
1  0  1  0  1  0  0  0  1  0  0  0  0  0  1  1  0  1  0  1  1  0  0  1  0
1  0  0  0  1  1  0  1  1  1  0  0  0  0  0  1  0  1  1  0  1  0  0  1  0
1  0  1  1  0  0  0  1  0  1  1  0  0  1  1  1  0  0  0  0  1  1  0  0  0
1  1  0  0  0  1  1  0  1  0  0  1  1  0  1  1  0  1  1  0  1  1  1  0  0
1  0  1  0  0  0  1  0  0  1  1  1  0  0  1  1  0  1  0  1  0  1  0  1  1
1  1  1  0  0  0  1  0  0  1  1  0  1  0  1  1  0  1  1  1  0  1  1  1  0
0  0  1  0  0  0  0  1  0  1  1  0  1  1  0  1  0  1  1  1  1  1  1  0  1
1  0  1  0  0  1  1  0  1  1  1  0  0  1  1  1  0  0  0  0  1  0  0  1  1
0  1  1  1  0  0  0  0  0  0  0  1  1  0  0  0  1  1  1  0  1  1  0  0  0
0  0  1  1  1  1  0  0  0  1  0  1  1  1  1  0  0  1  0  1  1  1  1  1  1
1  0  0  0  1  1  0  1  0  1  1  1  1  0  1  0  1  1  0  1  1  1  0  0  0
1  0  0  0  0  0  1  0  1  1  1  1  0  1  0  1  0  1  0  1  1  1  1  1  0
0  1  0  1  1  1  1  0  0  0  1  0  0  0  1  0  1  0  1  1  0  0  1  1  0
java.lang.ArrayIndexOutOfBoundsException: 25
at Corners.corners(Corners.java:18)
at Corners.main(Corners.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)```
I work in DrJava. Thank you very much!
Last edited by Ben Bublil; 04-23-2014 at 08:17 PM.

2. ## Re: I Need Help!

That's not a very informative post title, so people who might know how to fix your problem are less likely to click your post.

What is your actual problem? What does this code do? Does it compile? Does it generate a runtime error? Does it exhibit some strange behavior? Something else? Where is your MCVE?

3. ## Re: I Need Help!

what's wrong with this program?
Can you explain why you think there is something wrong?
Post the program's output and add some comments saying what is wrong with it and show what it should be.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•