虽然很多bug,还好能运行!满足了!
package javaSecondWeek;
import java.util.Scanner;
public class PolygonGraph {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String administer = "Younger";
String password = "Young123";
for (int a = 0; a < 3; a++) {
System.out.print("请输入用户名:");
String userName = scan.nextLine();
System.out.print("请输入密码:");
String psd = scan.nextLine();
if(userName.equals(administer)&&psd.equals(password)){
System.out.println("登陆成功");
System.out.println();
for (int b = 0; b < 3; b++) {
System.out.println("输入 1 制作正方形");
System.out.println("输入 2 制作倒直角三角形");
System.out.println("输入 3 制作正直角三角形");
System.out.println("输入 4 制作等腰三角形");
System.out.println("输入 5 制作倒等腰三角形");
System.out.println("输入 6 制作菱形");
System.out.println("输入 7 制作空心正方形");
System.out.println("输入 0 退出");
System.out.print("请输入对应的数字:");
int input = scan.nextInt();
if(input == 0){
break;
}else{
switch(input){
case 1:{
for (int i = 0; i < 4; i++) {//正方形
for (int j = 0; j < 4; j++) {
System.out.print("*"+" ");
}
System.out.println();
}
break;
}case 2:{
for (int i = 4; i > 0; i--) {//倒直角三角形
for (int j = 0; j < i; j++) {
System.out.print("*"+" ");
}
System.out.println();
}
break;
}case 3:{
for (int i = 0; i <= 4; i++) {//正直角三角形
for (int j = 0; j < i; j++) {
System.out.print("*"+" ");
}
System.out.println();
}
break;
}case 4:{
for (int i = 0; i < 4; i++) {//正等腰三角形13579
for (int j = 3; j > i; j--) {
System.out.print(" ");
}
for (int j2 = 0; j2 < 2*i+1; j2++) {
System.out.print("* ");
}
System.out.println();
}
break;
}case 5:{//倒等腰三角形
for (int i = 4; i > 0; i--) {
for (int j = 3; j > i-1; j--) {
System.out.print(" ");
}
for (int j = 0; j < 2*i-1; j++) {
System.out.print("* ");
}
System.out.println();
}
break;
}case 6:{
for (int i = 0; i < 3; i++) {//菱形13531
for (int j = 2; j > i; j--) {
System.out.print(" ");
}
for (int j2 = 0; j2 < 2*i+1; j2++) {
System.out.print("* ");
}
System.out.println();
}
for (int i = 2; i > 0; i--) {
for (int j = 2; j > i-1; j--) {
System.out.print(" ");
}
for (int j = 0; j < 2*i-1 ; j++) {
System.out.print("* ");
}
System.out.println();
}
break;
}case 7:{//空心正方形
System.out.print("请输入正方形的边长:");
int n = scan.nextInt();
for (int i = 0; i < n; i++) {
System.out.print("* ");
}
System.out.println();
for (int j = 0; j < n-2; j++) {
System.out.print("* ");
for (int i = 0; i < n-2; i++) {
System.out.print(" ");
}
System.out.println("* ");
}
for (int i = 0; i < n; i++) {
System.out.print("* ");
}
break;
}default:{
System.out.println("输入错误,请重新输入");
System.out.println();
continue;
}
}
}
break;
}
}else{
System.out.println("账号或密码错误,请重新输入");
continue;
}
break;
}
}
}