编辑代码

public class DemoForIf{
	public static void main(String[] args){
		/* int sum = 1;
		for(int i = 2;i <= 100;i++){
			if(i % 2 == 0){
				sum += i;
				System.out.print("偶数=" + i);
			}else if(i % 1 == 0){
				sum  -= i;
				
			}else{
				System.out.print("奇数=" + i);
			}
			
		}
		System.out.print("结果=" + sum); */
		
		/* java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.print("请输入一个正整数:");
		int sum = s.nextInt();
		int jieGuo = 1;
		for(int i = sum;i > 1;i--){
			jieGuo *= i;
		}
		System.out.print("结果为:" + jieGuo); */
		
		/* java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.print("请输入一个正整数:");
		int sum = s.nextInt();
		boolean zhiShu = true;
		for(int i = 2; i < sum; i++){
			if(sum % i == 0){
				zhiShu = false;
				break;
			}
		}
		System.out.println(sum+(zhiShu ? "是" : "不是") + "质数"); */
		
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.print("请输入一个正整数作为行数:");
		int sum = s.nextInt();
		for(int i = 1; i <= sum; i++){
			for(int j = 0; j < sum - i; j++){
				System.out.print(" ");
			}
			for(int k = 0; k < i * 2 - 1; k++){
				System.out.print("*");
			}
			System.out.println();

		}
    }
}