2017-02-17 88 views
-3

我很確定我的邏輯是正確的,但它不打印任何東西。任何人都可以看看我的代碼。它假設向後打印字符串。但它不打印任何東西。它也不給我一個錯誤。謝謝是否有可能從反向啓動for循環

String x = input.nextLine(); 

    for(int i = x.length()-1; i<=0;i--) 
    { 
    System.out.println(x.charAt(i)); 

    } 
+2

變化'[通過數組中的元素循環向後]的<=' to be '> =' – 4castle

+2

可能的複製(http://stackoverflow.com/ q/9379489/5743988) – 4castle

回答

1

<= vs >=。爲了向後你循環還應當檢查>=

for(int i = x.length()-1; i<=0;i--) 
    { 
    System.out.println(x.charAt(i)); 

    } 

應該是

for(int i = x.length()-1; i>=0;i--) 
    { 
    System.out.println(x.charAt(i)); 

    } 
+0

謝謝,所以這是一個邏輯錯誤再次感謝 –