题解 | #二维数组操作#
二维数组操作
https://www.nowcoder.com/practice/2f8c17bec47e416897ce4b9aa560b7f4
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int m = sc.nextInt();
int n = sc.nextInt();
if (m>9||n>9||m<=0||n<=0){
System.out.println(-1);
}else System.out.println(0);
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
if (isLegal(m,n,x1,y1)&&isLegal(m,n,x2,y2)){
System.out.println(0);
}else System.out.println(-1);
int x = sc.nextInt();
if(x<m){
if(m+1>9){
System.out.println(-1);
}else if(m+1<=9&&m+1>0) System.out.println(0);
}else{System.out.println(-1);}
int y = sc.nextInt();
if(y<n){
if (n+1>9){
System.out.println(-1);
}else if((n+1<=9)&&(n+1)>0)System.out.println(0);
}else{System.out.println(-1);}
int x3 = sc.nextInt();
int y3 = sc.nextInt();
if (isLegal(m,n,x3,y3)){
System.out.println(0);
}else System.out.println(-1);
}
}
public static boolean isLegal(int m ,int n,int x, int y) {
if ((x>=0)&&(x<=m-1)){
if ((y>=0)&&(y<=n-1)){
return true;
}
}
return false;
}
}//本题考查今后工作中理解用户、领导奇葩要求的能力