1:将1,2,3,4,5,6,7,8,9这九个数字分成三个百位数,
  每个数字用且只用一次,并且第三个数字是第一个的三倍,
  第二个数字是第一个的两倍。求三个数。【说明:结果可能多于一  组,例如:327,654,981】
2:根据给定的自然数,在控制台输出如下图形(下图指定为5):
   555555555
   544444445
  543333345
   543222345
  543212345
   543222345
   543333345
   544444445
   555555555求代码。

解决方案 »

  1.   

    MM的一定要顶,不过我思维太局限了。给出第一题代码,全排列做的,效率很慢大概要10秒才能计算出来
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.HashSet;
    import java.util.List;/*
     * 将1,2,3,4,5,6,7,8,9这九个数字分成三个百位数,
     * 每个数字用且只用一次,并且第三个数字是第一个的三倍,
     * 第二个数字是第一个的两倍。求三个数。【说明:结果可能多于一 组,例如:327,654,981】
     */
    public class Test {
    // 求阶乘:
    public static int factorial(int number) {
    if (number == 1) {
    return 1;
    }
    return factorial(number - 1) * number;
    } public static HashSet<Integer[]> splitNumber(Integer[] numbers) {
    List<Integer> list = Arrays.asList(numbers);
    HashSet<String> set = new HashSet<String>();
    HashSet<Integer[]> result = new HashSet<Integer[]>();
    while (set.size() < factorial(numbers.length)) {
    Collections.shuffle(list);
    Integer[] numberArray = new Integer[3];
    numberArray[0] = list.get(0) * 100 + list.get(1) * 10 + list.get(2);
    numberArray[1] = list.get(3) * 100 + list.get(4) * 10 + list.get(5);
    numberArray[2] = list.get(6) * 100 + list.get(7) * 10 + list.get(8);
    if(set.add(list.toString())){
    if(numberArray[0]*2==numberArray[1]&&numberArray[0]*3==numberArray[2]){
    result.add(numberArray);
    }
    }
    }
    return result;
    } public static void main(String[] args) {
    Integer[] numbers = {1,2,3,4,5,6,7,8,9};
    HashSet<Integer[]> result = splitNumber(numbers);
    for(Integer[] numberArray:result){
    System.out.println(Arrays.asList(numberArray));
    }
    }
    }输出结果:
    [273, 546, 819]
    [219, 438, 657]
    [192, 384, 576]
    [327, 654, 981]
      

  2.   

    第二题,接着来,这个简单public class Test2 {
    public static void printNumber(int number){
    int size = number*2-1;
    int[][] result= new int[size][size];
    for(int i=0;i<result.length;i++){
    for(int j=0;j<result[i].length;j++){
    int minrow=0;
    int maxrow=size-1;
    int mincol=0;
    int maxcol=size-1;
    int value=number;
    while(value>0){
    if(i==minrow||j==mincol||i==maxrow||j==maxcol){
    if(result[i][j]==0){
    result[i][j]=value;
    }
    }
    minrow++;
    maxrow--;
    mincol++;
    maxcol--;
    value--;
    }
    }
    }
    for(int i=0;i<result.length;i++){
    for(int j=0;j<result[i].length;j++){
    System.out.printf("%2d",result[i][j]);
    }
    System.out.println();
    }
    }
    public static void main(String[] args) {
    printNumber(9);
    }
    }
    输出测试:
     9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
     9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9
     9 8 7 7 7 7 7 7 7 7 7 7 7 7 7 8 9
     9 8 7 6 6 6 6 6 6 6 6 6 6 6 7 8 9
     9 8 7 6 5 5 5 5 5 5 5 5 5 6 7 8 9
     9 8 7 6 5 4 4 4 4 4 4 4 5 6 7 8 9
     9 8 7 6 5 4 3 3 3 3 3 4 5 6 7 8 9
     9 8 7 6 5 4 3 2 2 2 3 4 5 6 7 8 9
     9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9
     9 8 7 6 5 4 3 2 2 2 3 4 5 6 7 8 9
     9 8 7 6 5 4 3 3 3 3 3 4 5 6 7 8 9
     9 8 7 6 5 4 4 4 4 4 4 4 5 6 7 8 9
     9 8 7 6 5 5 5 5 5 5 5 5 5 6 7 8 9
     9 8 7 6 6 6 6 6 6 6 6 6 6 6 7 8 9
     9 8 7 7 7 7 7 7 7 7 7 7 7 7 7 8 9
     9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9
     9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
      

  3.   

    public static void main(String[] args) {    
         for (int i = 123;i<330;i++){
         String str = Integer.toString(i*1000000+i*2*1000+3*i);
         Pattern pattern = Pattern.compile("(\\d)(?!\\1)(\\d)(?!\\1|\\2)(\\d)(?!\\1|\\2|\\3)(\\d)(?!\\1|\\2|\\3|\\4)(\\d)(?!\\1|\\2|\\3|\\4|\\5)(\\d)(?!\\1|\\2|\\3|\\4|\\5|\\6)(\\d)(?!\\1|\\2|\\3|\\4|\\5|\\6|\\7)(\\d)(?!\\1|\\2|\\3|\\4|\\5|\\6|\\7|\\8)(\\d)$");
         Matcher match = pattern.matcher(str);
         if (match.matches())
         System.out.println(i+" "+2*i+" "+3*i);   
         }
        }
    正则表达式写的很丑,
    结果
    192 384 576
    219 438 657
    267 534 801
    273 546 819
    327 654 981
      

  4.   

    import java.util.*;
    public class T{
        public static void main(String[] args){
            Scanner cin=new Scanner(System.in);
            int i=cin.nextInt();
            for(int j=0;j<i;j++){
                int k=0;
                for(;k<j;k++){
                    if(i>9 && i-k<10)
                    System.out.print(" ");
                    System.out.print(i-k);
                }
                for(int l=0;l<2*i-2-2*k;l++){
                    if(i>9 && i-k<10)
                    System.out.print(" ");
                    System.out.print(i-k);
                }
                for(;k>=0;k--){
                    if(i>9 && i-k<10)
                    System.out.print(" ");
                    System.out.print(i-k);
                }
                System.out.println("");
            }
            for(int j=i-2;j>=0;j--){
                int k=0;
                for(;k<j;k++){
                    if(i>9 && i-k<10)
                    System.out.print(" ");
                    System.out.print(i-k);
                }
                for(int l=0;l<2*i-2-2*k;l++){
                    if(i>9 && i-k<10)
                    System.out.print(" ");
                    System.out.print(i-k);
                }
                for(;k>=0;k--){
                    if(i>9 && i-k<10)
                    System.out.print(" ");
                    System.out.print(i-k);
                }
                System.out.println("");
            }
        }
    }
    第二题的,不过超过十时有点难看...
      

  5.   

    借5楼思路写的,不用正则也可以很简单解决,谢啦!!import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;public class Test {
    public static void main(String[] args) {
    for(int i=123;i<333;i++){
    String str = Integer.toString(i*1000000+i*2*1000+i*3);
    ArrayList numbers = new ArrayList();
    for(int j=0;j<str.length();j++){
    numbers.add(str.charAt(j));
    }
    List list = Arrays.asList(new Character[]{'1','2','3','4','5','6','7','8','9'});
    if(numbers.containsAll(list)){
    System.out.println(i+","+i*2+","+i*3);
    }
    }
    }
    }输出结果:
    192,384,576
    219,438,657
    273,546,819
    327,654,981
      

  6.   

    import java.io.DataInputStream;public class Test5 {

    /**
     * 
     * @param num 输入的数字
     * @param arrLength  每个字符串的长度
     * @param index  数组的下标
     * @return 下标为index的字符窜
     */
    public String getString(int num,int arrLength,int index){

    StringBuilder str = new StringBuilder("");


    for(int i=0;i<index;i++){

    str.append(num);

    num--;
    }


    for(int i =0;i<arrLength-2*index;i++){

    str.append(num);
    }

    for(int i =0;i<index;i++){

    str.append(++num);
    }

    return str.toString();
    }

    public static void main(String [] args){

    System.out.println("请输入给定的自然数");

    int num = 5;

    DataInputStream dis = new DataInputStream(System.in);

            try{
            
             num = Integer.parseInt(dis.readLine());
             
             
             dis.close();
            
            }catch(Exception e){
            
            }

    int arrLength = 2*num-1;

    String []strNum = new String[arrLength];

    Test5 test = new Test5();

    for(int i=0;i<arrLength/2+1;i++){

    strNum[i] = test.getString(num,arrLength, i);

    strNum[arrLength-i-1] = strNum[i];
    }

    for(String str : strNum){

    System.out.println(str);
    }
    }}
      

  7.   

    public class Test {
        public static void main(String[] args) {
            final int NUM = 9;
            for (int i = 0 - (NUM - 1); i < NUM; i++) {
                for (int j = 0 - (NUM - 1); j < NUM; j++) {
                    System.out.print(Math.abs(i) >= Math.abs(j) ? Math.abs(i) + 1 : Math.abs(j) + 1);
                }
                System.out.println();
            }
        }
    }
      

  8.   

    小弟不才,还望解释一下这2句话的意思:
     String str = Integer.toString(i*1000000+i*2*1000+i*3);  定义这个是什么意思?
     for(int j=0;j<str.length();j++){
                    numbers.add(str.charAt(j));
                }
    这样numbers里面添加了0,1,2,3,4,5,6这7个元素
    后面
    if(numbers.containsAll(list)){
    这个如何理解,还望解释,谢谢·
      

  9.   

    懂了,非常谢谢啊·
    String str = Integer.toString(i*1000000+i*2*1000+i*3);对每个i进行如此运算,然后添加进入numbers里面,和
    List list = Arrays.asList(new Character[]{'1','2','3','4','5','6','7','8','9'});这个相比较,如何全部包括,则为真,也就满足str里面的数字都是一倍二倍三倍的条件,继而打印满足条件的数据·
      

  10.   

    先做了下第一题,搞了半个多小时/*
     * 将1,2,3,4,5,6,7,8,9这九个数字分成三个百位数,
     * 每个数字用且只用一次,并且第三个数字是第一个的三倍,
     * 第二个数字是第一个的两倍。求三个数。【说明:结果可能多于一 组,例如:327,654,981】
     */
    class Test1 {

    private boolean[] digit;

    public Test1( ) {
    digit = new boolean[10];
    }

    private void initial( ) {    //初始化数字数组,设置所有数字均为未用状态
    for( int i=1; i<10; i++ ) {
    digit[i] = true;
    }
    }

    private void use( int i ) {    //使用数字i,将其状态设置为已用
    digit[i] = false;
    }

    private boolean isRight( int first ) {  //测试第一个数字first是否合格
    int second = first * 2;
    int third = first * 3;
    int curDigit;
    while ( second > 0 ) {    //检查第二个数
    curDigit = second % 10;
    if ( curDigit == 0 ) {    //数位中有0,不合格,必须的
    return false;
    }
    if ( digit[curDigit] ) {    //curDigit还没有用到,将其改为已用
    use(curDigit);
    } else {
    return false;    //curDigit已经用了,所以first不合格
    }
    second /= 10;
    }
    while ( third > 0 ) {    //检查第三个数
    curDigit = third % 10;
    if ( curDigit == 0 ) {
    return false;
    }
    if ( digit[curDigit] ) {
    use(curDigit);
    } else {
    return false;
    }
    third /= 10;
    }
    return true;
    }

    private void start( ) {
    int first;
    for( int i=1; i<4; i++ ) {
    for( int j=1; j<10; j++ ) {
    if ( j==i ) {
    continue;
    }
    for ( int k=1; k<10; k++ ) {
    if ( k==i || k==j ) {
    continue;
    }
    //第一个数first要测试到所有可能的情况,所以有i,j,k三层循环
    initial();
    use(i);
    use(j);
    use(k);
    first = i*100 + j*10 + k;
    if ( isRight(first) ) {  // 如果正确,输出结果
    System.out.println( String.format( "%d  %d  %d",
    first, first*2, first*3 ) );
    }
    }
    }
    }


    public static void main( String[] args ) {
    Test1 sample = new Test1();
    sample.start();
    }
    }
      

  11.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace Console_whdtest
    {
        static void Main(string[] args)
        {
           #region 将1,2,3,4,5,6,7,8,9这九个数字分成三个百位数,每个数字用且只用一次,并且第三个数字是第一个的三倍, 第二个数字是第一个的两倍。求三个数。【说明:结果可能多于一 组,例如:327,654,981】
                /*
                 * 将1,2,3,4,5,6,7,8,9这九个数字分成三个百位数,每个数字用且只用一次,
                 * 并且第三个数字是第一个的三倍, 第二个数字是第一个的两倍。求三个数。
                 * 【说明:结果可能多于一 组,例如:327,654,981】
                 */
                //int[] iArr = new int[] {1,2,3,4,5,6,7,8,9 };
                int iNum = 0, jNum = 0, kNum = 0,fourth=0,fifth=0,six=0;
                string iStr=string.Empty;
                for(int i=1;i<=9;i++)
                    for (int j = 1; j <= 9; j++)
                    {
                        if (j == i) continue;
                        else
                        for (int k = 1; k <= 9; k++)
                        {
                            if (k == j || k == i) continue;
                            else
                            {
                                iNum = i * 100 + j * 10 + k;
                                iStr = i.ToString() + " " + j.ToString() + " " + k.ToString();
                                if (IsTrue(iNum, iStr, ref jNum, ref fourth, ref fifth, ref six))
                                {
                                    iStr += " " + fourth.ToString() + " " + fifth.ToString() + " " + six.ToString();
                                    if (IsTrue(iNum, jNum, iStr, ref kNum))
                                        Console.WriteLine(iNum + " | " + jNum + " | " + kNum);
                                }
                            }                        
                        }
                    }                    
                Console.ReadKey();
                
                #endregion
        } public static bool IsTrue(int _iNum, int _jNum, string _existsNum, ref int kNum)
            {
                int iNum = 0;
                for (int i = 1; i <= 9; i++)
                {
                    if (_existsNum.IndexOf(i.ToString()) != -1)
                        continue;
                    else
                    {
                        for (int j = 1; j <= 9; j++)
                        {
                            if (_existsNum.IndexOf(j.ToString()) != -1)
                                continue;
                            else
                            {
                                for (int k = 1; k <= 9; k++)
                                {
                                    if (_existsNum.IndexOf(k.ToString()) != -1)
                                        continue;
                                    else
                                    {
                                        iNum = i * 100 + j * 10 + k;
                                        if (iNum == (_iNum+_jNum))
                                        {
                                            kNum = iNum;
                                            return true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return false;
            }        public static bool IsTrue(int _num, string _existsNum,ref int jNum,ref int fourth, ref int fifth, ref int six)
            {
                int iNum=0;
                for (int i = 1; i <= 9; i++)
                {
                    if (_existsNum.IndexOf(i.ToString()) != -1)
                        continue;
                    else
                    {
                        for (int j = 1; j <= 9; j++)
                        {
                            if (_existsNum.IndexOf(j.ToString()) != -1)
                                continue;
                            else
                            {
                                for (int k = 1; k <= 9; k++)
                                {
                                    if (_existsNum.IndexOf(k.ToString()) != -1)
                                        continue;
                                    else
                                    {
                                        iNum = i * 100 + j * 10 + k;
                                        if (iNum > _num && iNum==(_num*2))
                                        {
                                            fourth = i;
                                            fifth = j;
                                            six = k;
                                            jNum = iNum;
                                            return true;
                                        }
                                    }                               
                                }
                            }                        
                        }   
                    }                                
                }
                return false;
                   
            }}
    结果:
    192 | 384 | 576
    219 | 438 | 657
    273 | 546 | 819
    327 | 654 | 981
    感觉这题有点意思,所以写了下,居然花了一个小时,唉,做事效率低啊!!
      

  12.   

    再做做第二题。20分钟啊……/**
     * 该类的作用是绘制你所要求的那样的矩形
     * 既然矩形都可以画,正方形当然也可以
     */
    class Test2 {

    private int length;    // 矩形的长
    private int width;    // 矩形的宽
    private int maxNum;    // 最外围的数字
    // 构造函数,忽略了可能抛出的异常
    public Test2( int length, int width, int maxNum ) { 
    this.length = length;
    this.width = width;
    this.maxNum = maxNum;
    }

    // 求出一点到最外围的点的最小距离(上下左右中最小的那个)
    private int distance( int x, int y ) {
    // 到左边的距离
    int ret = x;
    // 到右边的距离
    if ( length-1-x < ret ) {
    ret = length-1-x;
    }
    // 到上边的距离
    if ( y < ret ) {
    ret = y;
    }
    // 到下边的距离
    if ( width-1-y < ret ) {
    ret = width-1-y;
    }
    return ret;
    }

    // 绘图
    public void draw( ) {
    StringBuilder builder = new StringBuilder();
    int num;
    for( int i=0; i<length; i++ ) {
    for ( int j=0; j<length; j++ )
    {
    num = maxNum - distance(i,j);
    builder.append( String.format( "%3d", num ) );
    }
    builder.append( '\n' );
    }
    System.out.print( builder.toString() );
    }

    // 主函数
    public static void main( String[] args ) {
    Test2 sample = new Test2( 10, 10, 10 );
    sample.draw();
    }
    }
    测试结果:
     10 10 10 10 10 10 10 10 10 10
     10  9  9  9  9  9  9  9  9 10
     10  9  8  8  8  8  8  8  9 10
     10  9  8  7  7  7  7  8  9 10
     10  9  8  7  6  6  7  8  9 10
     10  9  8  7  6  6  7  8  9 10
     10  9  8  7  7  7  7  8  9 10
     10  9  8  8  8  8  8  8  9 10
     10  9  9  9  9  9  9  9  9 10
     10 10 10 10 10 10 10 10 10 10
      

  13.   


    public class Test { //此函数将打印 N N-1....N-j+1 N-j+1....N-j+1 N-j+2....N
    public static void PrintLine(int N,int j)
    {
    for (int i = 0;i<j;i++)
    {
    System.out.print(N - i);
    }
    for(int i = 0;i<2 * N - 1-2*j;i++)
    System.out.print(N-j+1);
    for (int i = 0;i<j;i++)
    {
    System.out.print(N - j + 1 + i);
    }
    System.out.println();
    }
    public static void PrintMiddleLine(int N)
    {
    for(int i = N;i>=1;i--)
    System.out.print(i);
    for(int i = 2;i<=N;i++)
    System.out.print(i);
    System.out.println(); } /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int N = 9;
    for(int i = 0;i <  N-1;i++)
    PrintLine(N,i+1);
    PrintMiddleLine(N);
    for(int i = 0;i <  N-1;i++)
    PrintLine(N,N-1-i); }}
      

  14.   

    public class Test { //此函数将打印 N N-1....N-j+1 N-j+1....N-j+1 N-j+2....N
    public static void PrintLine(int N,int j)
    {
    for (int i = 0;i<j;i++)
    {
    System.out.print(N - i);
    }
    for(int i = 0;i<2 * N - 1-2*j;i++)
    System.out.print(N-j+1);
    for (int i = 0;i<j;i++)
    {
    System.out.print(N - j + 1 + i);
    }
    System.out.println();
    }
    public static void PrintMiddleLine(int N)
    {
    for(int i = N;i>=1;i--)
    System.out.print(i);
    for(int i = 2;i<=N;i++)
    System.out.print(i);
    System.out.println(); } /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int N = 9;
    for(int i = 0;i <  N-1;i++)
    PrintLine(N,i+1);
    PrintMiddleLine(N);
    for(int i = 0;i <  N-1;i++)
    PrintLine(N,N-1-i); }}
      

  15.   


    public class Test1 {

    public static void DigitalCounting(int a,int[] counts)
    {
    while(a!=0)
    {
    counts[a%10]++;
    a/=10;
    }
    }
    public static boolean Checked(int[] as){
    int[] counts = new int[10];
    for(int i = 1;i<=9;i++)
    counts[i] = 0;
    for(int i = 0;i<as.length;i++)
    {
    DigitalCounting(as[i],counts);
    }
    for(int i = 1;i<10;i++)
    {
    if(counts[i]!=1)
    return false;
    }
    return true;
    }
    public static void main(String[] args) {
    //设第一个三位数为a,第二个为2a,第三个为3a,3a <=987 =>a<=329
    int[] as = new int[3];
    for(int a = 123;a<=329;a++)
    {
    as[0] = a;as[1] = 2 * a;as[2] = 3 *a;
    if(Checked(as))
    {
    System.out.println(a+" " + 2*a + " " + 3*a);
    }
    }
    }
    }
      

  16.   

    虽然不懂java,但是解题逻辑还是不难的。ps:一楼怎么知道lz是mm?
      

  17.   


    第一题就
    for i = 300 to 333
    {
        // 判断其本身、2倍和3倍数字是否重复(怎么判断?给一个数组a[10],开始初始化为0,已经被占用则为1)
        // 这样做效率还是不错的。
    }第二题
    也就是数组下标的控制而已。
      

  18.   

    c区求来的代码,看看其实这题和java无关了,是个算法题
    #define N    5
    void juzheng(int size);int main()
    {
        juzheng(N);
        system("pause");
        return 0;    
    }void juzheng(int size)
    {
        int k,i,j,num=1;
        int a[N*2][N*2]={0};
        for(i=size;i>0;i--)
        {
            for(j=1;j<size*2;j++)
            {
                a[i][j]=num;
                a[j][i]=num;
                a[size*2-i][j]=num;
                a[j][size*2-i]=num;
            }
            num++;
        }    
        for(i=1;i<size*2;i++)
        {    
            for(j=1;j<size*2;j++)
            {
                printf("%d",a[i][j]);
            }
            printf("\n");
        }
    }
      

  19.   

    //add 1-9 as String to HashSet
    Set<String> keys = new HashSet<String>();
    for (int i = 1; i < 10; i++) {
    keys.add(""+i);
    } int second, third;
    StringBuffer sBuffer;
    boolean isMatch; for (int first = 123; first < 330; first++) {
    sBuffer = new StringBuffer();
    second = 2*first;
    third = 3*first;
    //append first, second and third as a String
    sBuffer.append(first);
    sBuffer.append(second);
    sBuffer.append(third);
    isMatch = true;
    //test if sBuffer contains all number in HashSet
    for (String s : keys) {
    if (sBuffer.indexOf(s) == -1){
    isMatch = false;
    break;
    }
    }
    if (isMatch) {
    System.out.println(first + ": " + second + ": " + third);
    }
    }输出: 
    192: 384: 576
    219: 438: 657
    273: 546: 819
    327: 654: 981
      

  20.   

    第一题如下:public class Test1 {
    public int[] data = new int[10];
    public void dfs(int n) {
    if (n > 9) {
    int s1 = data[1] * 100 + data[2] * 10 + data[3];
    int s2 = data[4] * 100 + data[5] * 10 + data[6];
    int s3 = data[7] * 100 + data[8] * 10 + data[9];
    if ((s2 == s1 * 2) && (s3 == s1 * 3)) {
    System.out.println("[" + s1 + "," + s2 + "," + s3 + "]");
    }
    } else {
    for (int i = 1, j = 1; i <= 9; i++) {
    for (j = 1; j < n; j++) {
    if (data[j] == i) {
    break;
    }
    }
    if (j >= n) {
    data[n] = i;
    dfs(n + 1);
    }
    }
    }
    }
    public static void main(String[] args) {
    Test1 test = new Test1();
    test.dfs(1);
    }
    }测试结果:
    [192,384,576]
    [219,438,657]
    [273,546,819]
    [327,654,981]
    第二题如下:import java.util.Scanner;
    public class Test2 {
    public static void main(String[] args) {
    System.out.print("请输入矩阵的阶数:");
    Scanner sc = new Scanner(System.in);
    int m = sc.nextInt(), n = 2 * m - 1;
    int[][] data = new int[n + 1][n + 1];
    int x = 1, y = n;
    for (int k = m; k >= 1; k--) {
    for (int j = x; j <= n - x + 1; j++) {
    data[x][j] = k;
    data[y][j] = k;
    data[j][x] = k;
    data[j][y] = k;
    }
    x++;
    y--;
    }
    for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
    System.out.print(data[i][j]);
    }
    System.out.println();
    }
    }
    }测试结果如下:
    请输入矩阵的阶数:7
    7777777777777
    7666666666667
    7655555555567
    7654444444567
    7654333334567
    7654322234567
    7654321234567
    7654322234567
    7654333334567
    7654444444567
    7655555555567
    7666666666667
    7777777777777
      

  21.   

    这部分代码,我是运行了20秒,还以为出问题了。真的很不错,lacus87 谢谢了,学习~~~~
    佩服火龙果,精简的代码,速度超快~~~~  
    多谢多谢了