我在java中做了樓梯案例問題。我寫了它,但它沒有奏效。所以我張貼它,如果有人可以檢查我的錯誤。謝謝。樓梯不工作,有我的代碼中的錯誤
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int f=n;
for(int i=0;i<n;i++)
{
for(int j=0;i<f;j++)
{
System.out.print(" ");
}
for(int k=0;k<=i;k++)
{
System.out.print("#");
}
f=f-1;
System.out.println(" ");
}
}
輸入爲6
和輸出模式應該是
#
##
###
####
#####
######
,但該礦沒有產生任何 代碼是固定的代碼應該已經
公共靜態void main(String [] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int f=n;
for(int i=0;i<n;i++)
{
for(int j=1;j<f;j++)
{
System.out.print(" ");
}
for(int k=0;k<=i;k++)
{
System.out.print("#");
}
f=f-1;
System.out.println(" ");
}
}
感謝所有幫助傢伙......幸運,有這樣一個社區.. :)
是否沒有輸出或輸出很多空間? – dave
歡迎來到堆棧溢出!它看起來像你需要學習使用調試器。請幫助一些[互補調試技術](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果您之後仍然遇到問題,請隨時回答一個更具體的問題。 –