打印
import java.util.Scanner;
public class MenuPrint {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("=功能菜单=");
System.out.println("A. 打印直线");
System.out.println("B. 打印杨辉三角形");
System.out.print("请输入选项(A/B):");
String choice = sc.next().toUpperCase();
if ("A".equals(choice)) {
System.out.print("请输入直线长度:");
int len = sc.nextInt();
for (int i = 0; i < len; i++) {
System.out.print("*");
}
} else if ("B".equals(choice)) {
System.out.print("请输入行数:");
int row = sc.nextInt();
int[][] yh = new int[row][row];
for (int i = 0; i < row; i++) {
yh[i][0] = 1;
yh[i][i] = 1;
for (int j = 1; j < i; j++) {
yh[i][j] = yh[i-1][j-1] + yh[i-1][j];
}
for (int j = 0; j <= i; j++) {
System.out.print(yh[i][j] + " ");
}
System.out.println();
}
} else {
System.out.println("输入选项错误!");
}
sc.close();
}
}
浙公网安备 33010602011771号