JAVA回形数
作者:互联网
1 package test; 2 3 import java.util.Scanner; 4 5 public class test { 6 public static void main(String[] args) { 7 Scanner scanner=new Scanner(System.in); 8 System.out.println("请输入个数:"); 9 int num=scanner.nextInt(); 10 int[][] l=new int[num][num]; 11 int co=0; 12 int q; 13 if(num%2==0) { 14 q=num/2; 15 }else { 16 q=(num-1)/2; 17 } 18 int f=1; 19 for(int j=0;j<q;j++) { 20 int i1=0,i2=0,i3=0,i4=0; 21 for(int i=0;i<num-1-j*2;i++) { 22 i1=l[j][i+j]=i+f; 23 } 24 25 for(int i=0;i<num-1-j*2;i++) { 26 i2=l[i+j][num-1-j]=i1+i+1; 27 } 28 for(int i=0;i<num-1-j*2;i++) { 29 i3=l[num-1-j][num-1-j-i]=i2+i+1; 30 } 31 for(int i=0;i<num-1-j*2;i++) { 32 i4=l[num-i-1-j][j]=i3+i+1; 33 } 34 f=i4+1; 35 System.out.println("F为"+f); 36 } 37 for(int j=0;j<num;j++) { 38 for(int i=0;i<num;i++) { 39 System.out.print(l[j][i]+"\t"); 40 } 41 System.out.println(); 42 } 43 } 44 }
标签:JAVA,Scanner,int,System,num,形数,test,scanner 来源: https://www.cnblogs.com/ccwme/p/15418969.html