用Java程序输出以下图案
(1)(2)(3)(4)************************************************************...
(1) (2) (3) (4)
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * 展开
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * 展开
2个回答
展开全部
(1)
for (int i = 1; i <= 5; i++) {
for (int j = 6 - i; j <= 5; j++) {
System.out.print("*");
}
System.out.println();
}
(2)
for (int i = 1; i <= 5; i++) {
for (int j = i; j <= 5; j++) {
System.out.print("*");
}
System.out.println();
}
(3)
for (int i = 1; i <= 5; i++) {
for (int k = 0; k < i - 1; k++) {
System.out.print(" ");
}
System.out.print(" ");
for (int j = i; j <= 5; j++) {
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
(4)
for (int i = 1; i <= 5; i++) {
for (int k = i; k <= 5; k++) {
System.out.print(" ");
}
for (int j = 6 - i; j <= 5; j++) {
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
for (int i = 1; i <= 5; i++) {
for (int j = 6 - i; j <= 5; j++) {
System.out.print("*");
}
System.out.println();
}
(2)
for (int i = 1; i <= 5; i++) {
for (int j = i; j <= 5; j++) {
System.out.print("*");
}
System.out.println();
}
(3)
for (int i = 1; i <= 5; i++) {
for (int k = 0; k < i - 1; k++) {
System.out.print(" ");
}
System.out.print(" ");
for (int j = i; j <= 5; j++) {
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
(4)
for (int i = 1; i <= 5; i++) {
for (int k = i; k <= 5; k++) {
System.out.print(" ");
}
for (int j = 6 - i; j <= 5; j++) {
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
展开全部
public class Test {
//程序入口
public static void main(String[] args) {
int n = cnt + 1;
for (int i = 0; i < n; i++) {
printStar(i);
}
for (int i = n; i-- != 0;) {
printStar(i);
}
for (int i = 0; i < n; i++) {
printStar2(i);
}
for (int i = n; i-- != 0;) {
printStar2(i);
}
}
public static final int cnt = 5;//这个是实际循环次数
public static void printStar(int n) {
for (int i = 0; i < n; i++)
System.out.print("* ");
System.out.println();
}
public static void printStar2(int n) {
for (int i = 0; i < n; i++)
System.out.print(" ");
for (int i = 5 - n; i-- != 0;) {
System.out.print("* ");
}
System.out.println();
}
}
//程序入口
public static void main(String[] args) {
int n = cnt + 1;
for (int i = 0; i < n; i++) {
printStar(i);
}
for (int i = n; i-- != 0;) {
printStar(i);
}
for (int i = 0; i < n; i++) {
printStar2(i);
}
for (int i = n; i-- != 0;) {
printStar2(i);
}
}
public static final int cnt = 5;//这个是实际循环次数
public static void printStar(int n) {
for (int i = 0; i < n; i++)
System.out.print("* ");
System.out.println();
}
public static void printStar2(int n) {
for (int i = 0; i < n; i++)
System.out.print(" ");
for (int i = 5 - n; i-- != 0;) {
System.out.print("* ");
}
System.out.println();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询