java 5X5数字的排列
1 import java.util.Scanner; 2 public class xxx { 3 4 public static void main(String[] args) { 5 Scanner sc=new Scanner(System.in); 6 System.out.print("请输入这五个数据:"); 7 int a[][]=new int [5][5]; 8 int b[]=new int [5]; 9 int i,j; 10 for (i=0;i<b.length;i++) 11 { 12 b[i]=sc.nextInt(); 13 } 14 for (i=0;i<a.length;i++) 15 { 16 for(j=0;j<a[i].length;j++) 17 { 18 a[i][j]=b[(i+j)%5]; 19 System.out.print(a[i][j]+" "); 20 } 21 System.out.println(); 22 } 23 } 24 25 }
首先确定好数组,一维数组来确定所输入的数,二维数组来确定“表格”,先定义再声明,根据他们的关系来循环遍历,最后在输出最终结果


浙公网安备 33010602011771号