您的程式被監控系統中斷,可能是程式無法正常結束所導致。 Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1347) at code_1245900.main(code_1245900.java:9)
我不懂它是啥意思
以下是小弟我的程式碼
剛入門JAVA所以不太會寫import java.util.Scanner; public class d625 { public static void main(String[] args){ Scanner s = new Scanner(System.in); while(s.hasNextInt()){ int x = s.nextInt(); char a[][] = new char[x][x]; for(int i =0;i<x;i++){ Scanner row = new Scanner(System.in); String str = row.next(); char ch[] = str.toCharArray(); for(int n =0;n<ch.length;n++){ a[i][n] = ch[n]; } } char b[][] = new char[x+2][x+2]; for(int i = 0;i<x;i++){ for(int j = 0;j<x;j++){ b[i+1][j+1] = a[i][j]; } } int count = 0; int c[][] = new int[x+2][x+2]; for(int i = 1;i<x+1;i++){ for(int j = 1;j<x+1;j++){ for(int k =-1;k<=1;k++){ for(int l =-1;l<=1;l++){ if(k==0&&l==0) continue; else if(b[i-k][j-l]=='*') count = count+1; } } c[i][j] = count; //if(count==0) // c[i][j] = '-'; count = 0; } } char d[][] = new char[x+2][x+2]; for(int i = 1;i<x+1;i++){ for(int j = 1;j<x+1;j++){ if(b[i][j]=='*') d[i][j] = '*'; else if(c[i][j]==0){ c[i][j] = '-'; d[i][j] = (char) c[i][j]; } else d[i][j] = (char)(48+c[i][j]); } } for(int i =1;i<x+1;i++){ for(int j =1;j<x+1;j++){ System.out.print(d[i][j]); } System.out.println(); } } } }