package test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("printparallelogram");
System.out.println("printtriangle");
System.out.println("Input your choice");
int choice = scanner.nextInt();
if (choice == 1) {
System.out.println("Input x:");
int x = scanner.nextInt();
System.out.println("Input y:");
int y = scanner.nextInt();
drawing(x, y);
} else if (choice == 2) {
System.out.println("Input x:");
int x = scanner.nextInt();
drawing(x);
}
}
/**
* 平行四边形
*
* @param x
* @param y
*/
public static void drawing(int x, int y) {
// 外层循环 每次打出一个*
for (int i = 1; i <= x; i++) {
// 填充空格
for (int j = 1; j <= x - i; j++) {
System.out.print(" ");
}
// 内层循环 每次打印一个*
for (int k = 1; k <= y; k++) {
System.out.print("*");
}
System.out.println();
}
}
/**
* 三角形
*
* @param x
*/
public static void drawing(int x) {
// a 控制行
for (int i = 0; i < x; i++) {
for (int j = 0; j < x - i; j++)// 输出空格随着循环是递减的
{
System.out.print(" ");
}
for (int k = 0; k <= i * 2; k++)// 输出*号随着外循环是递增的
{
System.out.print("*");
}
System.out.println();
}
}
}