1. 程式人生 > >列印一個有n層的直角三角形(Java)

列印一個有n層的直角三角形(Java)

package firstclasss;
import java.util.*;;

public class HelloData {
	
	public int PrintTriangle(int n){
		int last = 0 ;
		for(int i = 1 ; i<= n ; i++){
			for(int j = 1 ; j <= i ; j ++){
				last++;
				System.out.printf("%02d ",last);
			}
			System.out.println();
		}
		return last;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HelloData data = new HelloData();
		int lastnum;
		lastnum = data.PrintTriangle(5);
		System.out.println("lastnum = "+lastnum);
	}

}