java编写程序根据用户输入的整数来在屏幕上产生图形
3个回答
2013-12-25
展开全部
int max=5;
String space="";
for (int i=1; i < max; i++) {
space +=" ";
}
String star = "";
for(int i=0;i<5;i++){
star += "*";
System.out.println(space + star);
}
for(int i=max;i> 0;i--){
space = "";
for (int j = max; j > i; j--) {
space += " ";
}
star = "";
for (int j = 0; j < i; j++) {
star += "*";
}
System.out.println(space + star );
}
或者
final int max=5;
String space="";
for (int i=1; i < max; i++) {
space +=" ";
}
String star = "";
for(int i=0;i<5;i++){
star += "*";
System.out.println(space + star);
}
String spaceL = "";
String starL = "";
for (int i=0; i < max; i++) {
spaceL += " ";
starL += "*";
}
for (int i = 0; i < max; i++) {
System.out.print(spaceL.substring(max-1-i, max-1));
System.out.println(starL.substring(i, max-1));
}
或者
final int max=6;
String spaceL = "";
String starL = "";
for (int i=0; i < max; i++) {
spaceL += " ";
starL += "*";
}
for (int i = 0; i < max; i++) {
System.out.println(spaceL.substring(0, max-2) + starL.substring(max-1-i, max-1));
}
for (int i = 0; i < max; i++) {
System.out.println(spaceL.substring(max-1-i, max-1)+starL.substring(i, max-1));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String x = ""
for(int i=0;i<5;i++){
x+="*";
println(x);
}
for(int i=5;i>0;i++){
x-="*";
println(x);
}
不知道行不行
for(int i=0;i<5;i++){
x+="*";
println(x);
}
for(int i=5;i>0;i++){
x-="*";
println(x);
}
不知道行不行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int a;
System.out.print("请输入一个整数:");
BufferedReader strin = new BufferedReader(new InputStreamReader(
System.in));
a = Integer.parseInt(strin.readLine());
String space = "";
String star = "";
for (int i = 1; i <= a; i++) {
space += " ";
}
for (int i = 1; i <= a * 2; i++) {
if (i <= a) {
star += "*";
System.out.println(space + star);
}
else if (i==a+1){
star+="*";
System.out.println(star);
star=star.replaceFirst("\\*", " ");
}
else if(i>(a+1)){
star=star.replaceFirst("\\*", " ");
System.out.println(star);
}
}
System.out.print("请输入一个整数:");
BufferedReader strin = new BufferedReader(new InputStreamReader(
System.in));
a = Integer.parseInt(strin.readLine());
String space = "";
String star = "";
for (int i = 1; i <= a; i++) {
space += " ";
}
for (int i = 1; i <= a * 2; i++) {
if (i <= a) {
star += "*";
System.out.println(space + star);
}
else if (i==a+1){
star+="*";
System.out.println(star);
star=star.replaceFirst("\\*", " ");
}
else if(i>(a+1)){
star=star.replaceFirst("\\*", " ");
System.out.println(star);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询