题解 | #二维数组操作#

二维数组操作

https://www.nowcoder.com/practice/2f8c17bec47e416897ce4b9aa560b7f4

//要注意下标...

package OnlineTest.easy;


import java.util.Scanner;

public class HJ83 {
    static int row = 0;
    static int col = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            row=0;
            col=0;
            CreatMarix(sc.nextInt(), sc.nextInt());
            ChangeLocatio(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
            CreatRow(sc.nextInt());
            CreaCol(sc.nextInt());
            Search(sc.nextInt(), sc.nextInt());
        }
    }

    public static void CreatMarix(int m, int n) {

        if (m <= 9 && n <= 9) {
            row = m;
            col = n;
            System.out.println(0);
        } else {
            System.out.println(-1);
        }
    }

    public static void ChangeLocatio(int x1, int y1, int x2, int y2) {

        if ((0 <= x1 && x1 <= row-1) && (0 <= y1 && y1 <= col-1) && (0 <= x2 && x2 <= row-1) && (0 <= y2 && y2 <= col-1)) {
            System.out.println(0);
        } else {
            System.out.println(-1);
        }
    }

    public static void CreatRow(int r) {

        if (row < 9&& r<=row-1) {
//            row+=1;
            System.out.println(0);
        } else {
            System.out.println(-1);

        }
    }

    public static void CreaCol(int c) {
        if (col < 9 &&c<=col-1) {
//            col+=1;
            System.out.println(0);
        } else {
            System.out.println(-1);
        }
    }

    public static void Search(int i, int j) {
        if ((0 <= i && i <= row - 1) && (0 <= j && j <= col - 1)) {
            System.out.println(0);
        } else {
            System.out.println(-1);
        }
    }


}

全部评论

相关推荐

点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务