将二维数组类型由整型改成字符串型,结果赋值时总是跳过第一个数从第二个开始赋值
程序代码:
import java.util.Scanner; public class 数组 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); System.out.println("请输入二维数组的行数:"); int left=in.nextInt(); System.out.println("请输入二维数组的列数:"); int right=in.nextInt(); int i,j = 0; String [][] anArray=new String[left][right]; System.out.println("请为此二维数组赋值:"); for(i=0;i<left;i++) for(j=0;j<right;j++) anArray[i][j]=in.nextLine(); Shuzu(left,right,anArray); } public static void Shuzu(int left,int right,String anArray[][]) { System.out.println("二维数组输出:"); int i,j; int m,n; for(i=0;i<left;i++) for(j=0;j<right;j++) { m=i+1; n=j+1; System.out.println("第"+m+"行"+n+"列:"); System.out.println(anArray[i][j]+" "); } } }