求打印三角形的代码
要求控制台打印出*
* *
* * *
* * * *
* * * * *
public class Triangle { public static void main(String[] args) { printTriangle(5); } public static void printTriangle(int line) { for (int i = 0 ;i <= line ;i++) { for (int j = 0; j < line - i; j++) { System.out.print(" "); } for (int x = 0;x < 2*i-1; x++ ) { if(x%2==0) System.out.print("*"); else System.out.print(" "); } System.out.println(); } } }