Two-dimensional array triangular error question

Asked 2 years ago, Updated 2 years ago, 137 views

There's an error in writing down the two-dimensional array cedar coding in the book, but I can't find the reason.

import java.util.*;

 public class Coderunner {
    public static void main(String[]args){
        char[][] board = new char[3][3];
        int x,y;

        Scanner scan = new Scanner(System.in);

        for(int i=0; i<3; i++){ 
            for(int j=0; j<3; j++){
                board[i][j] = ' ';
            } 
        } 

        do{ 
            for(int i=0; i<3; i++) { 
                System.out.println(" " + board[i][0] + "1 " + board[i][1] +
                                                "1 " + board[i][2]);                
                if(i != 2) 
                    System.out.println("---1---1---");             

            }             

            System.out.print("insert your next coordinates");
            x = scan.nextint();
            y = scan.nextint();

            if(board[x][y] !=' ') { 
                system.out.println("wrong location");
               continue;
            } } else
                board[x][y] = 'x';

            int i=0, j=0;
            for(i=0; i<3; i++) {
                for(j=0; j<3; j++) {
                    if(board[i][j] == ' ') 
                        break;
                } 
                if(board[i][j] == ' ') 
                    break;
            } 
            if(i<3 && j<3) { 
                board[i][j] = 'o';
            } 
        } } while(true);

    }
} 

Error is

/Coderunner.java:51: error: cannot find symbol
x = scan.nextint();
^


symbol: method nextint()
location: variable scan of type Scanner
/Coderunner.java:53: error: cannot find symbol
y = scan.nextint();
^


symbol: method nextint()
location: variable scan of type Scanner
2 errors

2d-array java

2022-09-22 12:36

2 Answers

It's not the nextint() function, but the nextInt() function.


2022-09-22 12:36

// Enter your code here
if(scan.hasNextInt()){
   x = scan.nextInt();
   y = scan.nextInt();
}
else{
   x = 0;
   y = 0;
}


2022-09-22 12:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.