mercredi 28 septembre 2016

if statement producing gibberish output

I have a java assignment that is asking for a code that tells the user to enter a point (row and column or x and y) and the program outputs all possible moves for the chess' knight.

package datastructureass1;
import java.util.Scanner;

public class DataStructureAss1 {

    public static void main(String[] args) {
       Scanner cin = new Scanner (System.in);
        
        int knight[][]= new int [7][7];
            
                     System.out.println("Please enter the knight's position starting with rows followed by columns");
                       int i=cin.nextInt();      
                       int j=cin.nextInt();
                        
                        i=i+2;
                        j=j+1;
                        if (i<=8&&j<=8)
                     
                           System.out.println( "{"+knight[i]+","+knight[j]+"}");
                       
                        i= i+2;
                        j=j-1;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");
                            
                        i= i-2;
                        j=j+1;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");
                        i= i-2;
                        j=j-1;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");   
                            
                        i= i+1;
                        j=j+2;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");
                        i= i+1;
                        j=j-2;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");
                        i= i-1;
                        j=j+2;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");    
                        i= i-1;
                        j=j-2;
                        if (i<=8&&j<=8);
                            System.out.println( "{"+knight[i]+","+knight[j]+"}");
                         
    }
                            
                 }
                 
            
        
       

when i run this in netbeans it gives me this kind of output: {[I@6ac1abcf,[I@6ac1abcf}

{[I@50f6d9ca,[I@7e54864c}

{[I@6ac1abcf,[I@6ac1abcf}

{[I@5f3d285f,[I@7e54864c}

{[I@7e54864c,[I@2825a5d2}

{[I@6ac1abcf,[I@7e54864c}

{[I@7e54864c,[I@2825a5d2}

it doesnt make sense and i dont know what i did wrong in my code!

Aucun commentaire:

Enregistrer un commentaire