首页 > ACM题库 > HDU-杭电 > hdu 2123 An easy problem[解题报告]java
2013
12-29

hdu 2123 An easy problem[解题报告]java

An easy problem

问题描述 :

In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j.

输入:

The first line of input is an integer C which indicate the number of test cases.

Then C test cases follow.Each test case contains an integer N (1<=N<=9) in a line which mentioned above.

输出:

The first line of input is an integer C which indicate the number of test cases.

Then C test cases follow.Each test case contains an integer N (1<=N<=9) in a line which mentioned above.

样例输入:

2
1
4

样例输出:

1
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16

Hint
There is no blank space at the end of each line.

import java.util.Scanner;
public class Main{	
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int N=input.nextInt();
		while(N-->0){
			int n=input.nextInt();
			for(int i=1;i<=n;i++){
				System.out.print(i);
				for(int j=2;j<=n;j++){
					System.out.print(" "+i*j);
				}
				System.out.println();
			}
		}
	}
}

解题转自:http://blog.csdn.net/zhangyiacm/article/details/9002122


  1. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。