0
我想創建一個鑽石形狀(由星號組成),但是我似乎無法得到右下腿的右下角?爲什麼我的代碼不正確?在此先感謝初學Java控制循環不產生期望的結果
import java.util.Scanner;
public class Diamond
{
public static void main(String[] args)
{
System.out.println("Enter the size of the diamond and press enter:");
Scanner kb = new Scanner(System.in);
int N = kb.nextInt();
for (int c0 = 1; c0 <= N; c0++) // establishes the number of lines in the diamond
{
for (int c1 = 0; c1 <= N-1-c0; c1++) System.out.print(" "); // establishes the number of spaces before each asterisk
System.out.print("*");
for (int c2 = 3; c2 <= c0*2; c2++) System.out.print(" "); //adds a space between both asterisks. This boolean check repeats for each line
System.out.print("*");
System.out.println();
}
for (int c0 = 1; c0 <= N; c0++) // establishes the number of lines in the diamond
{
for (int c1 = N; c1 >= N+2-c0; c1--) System.out.print(" "); // establishes the number of spaces before each asterisk
System.out.print("*");
for (int c2 = N*2; c2 >= c0+2; c2--) System.out.print(" "); //adds a space between both asterisks. This boolean check repeats for each line
System.out.print("*");
System.out.println();
}
}
}
這個做了TRIC ķ。我還沒有學過那些其他的東西,但是你對我現有的代碼的修復是有用的 – skellyboy