I am trying to make a code for finding out the inverse of a matrix but something is wrong....can anybody please help me with this...Here's the code:

import java.util.Scanner;
public class mainclass
{
 
 
	public static void main(String str[])
	{
		Scanner in = new Scanner(System.in);
		int num;
 
		System.out.println("Enter rows/columns : ");
		num = in.nextInt();
 
 
		double A[][] = new double[num][num];
		double B[][] = new double[num][num];
 
 
		for(int i=0;i<num;i++)
			for(int j=0;j<num;j++)
			{
				System.out.println("Enter element " + "["+i+"]"+"["+j+"]");
				A[i][j] = in.nextDouble();
			}
 
		for(int i=0;i<num;i++)
			for(int j=0;j<num;j++)
			{
				if(i==j)
				{
					B[i][j] = 1;
				}
 
				else
				{
					B[i][j] = 0;
				}
			}
 
label1:	for(int i=0;i<num;i++)
		{
			if(i%2==0)
			{
label2:			for(int j=0;j<num;j++)
				{
					if(j==i)
					{
						if(A[j][i]>1 || A[j][i]<1)
						{
label3:				        for(int k=0;k<num;k++)
							{
								if(k!=j)
								{
									double div = (A[j][i]-1)/A[k][i];
 
									for(int l=0;l<num;l++)
									{
										A[j][l]=A[j][l]-(div*A[k][l]);
										B[j][l]=B[j][l]-(div*B[k][l]);
									}
									continue label2;
 
 
								}
								else
									continue label3;
							}
 
						}
						else
							continue label2;
 
					}
					else
					{
						if(A[j][i]!=0)
						{   
label:						for(int k=0;k<num;k++)
							if(k!=j)
							{
 
							{
								double div = A[k][i]/A[j][i];
								for(int l=0;l<num;l++)
								{
									A[j][l]=A[j][l]-(div*A[k][l]);
									B[j][l]=B[j][l]-(div*B[k][l]);
								}
 
							}
							break label;
							}
							else
							{
								continue label;
							}
						}
 
						else
							continue label2;
 
 
 
					}
				}	
 
			}
			else
			{
label4:		for(int j=num-1;j>=0;j--)
				{
					if(j==i)
					{
						if(A[j][i]>1 || A[j][i]<1)
						{
label5:						for(int k=0;k<num;k++)
							{
								if(k!=j)
								{
									double div = (A[j][i]-1)/A[k][i];
 
									for(int l=0;l<num;l++)
									{
										A[j][l]=A[j][l]-(div*A[k][l]);
										B[j][l]=B[j][l]-(div*B[k][l]);
									}
									break label5;
 
 
								}
								else
									continue label5;
							}
 
						}
						else
							continue label4;
 
					}
					else
					{
						if(A[j][i]!=0)
						{
label6:						for(int k=0;k<num;k++)
							if(k!=j)
							{
 
 
								double div = A[k][i]/A[j][i];
 
								for(int l=0;l<num;l++)
								{
									A[j][l]=A[j][l]-(div*A[k][l]);
									B[j][l]=B[j][l]-(div*B[k][l]);
								}
 
 
 
							break label6;
							}
						}
 
						else
							continue label4;
 
 
 
					}
				}
 
 
 
			}
 
		}
 
			System.out.println("The inverted matrix is : ");
 
			for(int i=0;i<num;i++)
			{
				System.out.println("");
				for(int j=0;j<num;j++)
				{
					System.out.print(B[i][j]+ " ");
				}
 
			}		
 
 
	}
}