本人一初学Java ,,我想通过在控制台输入数字 来打印星号。调试后显示一错误:找不到符号,求解:
importjava.io.*;publicclassdemo21{publicstaticvoidmain(Stringargs[]){try{InputStreamR...
import java.io.*;
public class demo21{
public static void main(String args[]){
try{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("输入第一个数");
String a1=br.readLine();
}
catch(Exception e)
{
e.printStackTrace();
}
class Per{
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();
}
}
}
Per o1=new Per();
o1.demo(a1);
}} 展开
public class demo21{
public static void main(String args[]){
try{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("输入第一个数");
String a1=br.readLine();
}
catch(Exception e)
{
e.printStackTrace();
}
class Per{
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();
}
}
}
Per o1=new Per();
o1.demo(a1);
}} 展开
1个回答
展开全部
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();
}
}
}
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();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询