...来打印星号。调试后显示一错误:找不到符号,求解:
发布网友
发布时间:2024-10-22 07:45
我来回答
共1个回答
热心网友
时间:2024-11-17 07:47
import java.io.*;
public class demo21 {
public static void main(String args[]) {
demo21 test = new demo21();
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("输入第一个数");
String a1 = br.readLine();
int input = Integer.parseInt(a1);
test.demo(input);
} catch (Exception e) {
e.printStackTrace();
}
}
public void demo(int a) {
for (int i = 1; i <= 4; i++) {
for (int k = 1; k <= 4 - i; k++) {
System.out.print(" ");
}
for (int j = 1; j <= (i - 1) * 2 + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}