本文介紹了Java 錯誤,重復的局部變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試調試分配的一部分代碼(我對 Java 還是很陌生)并且已經梳理了許多資源來解決這個沖突,但仍然不能完全解決.
I'm trying to debug a portion of code for an assignment (I'm still very new to Java) and have combed through many resources to solve this conflict but still can't quite work it out.
public static void main(String [] args){
Scanner keyboard = new Scanner(System.in);
String input = null;
do
{
System.out.println("Enter 'A' for option A or 'B' for option B.");
String input = keyboard.next();
input.toLowerCase();
input.charAt(0);
}
while ((input != "a") || (input != "b"));
}
輸入字符串總是出現重復的局部變量錯誤.
I always get a Duplicate Local Variable error with the input String.
任何幫助將不勝感激!
推薦答案
替換
String input = keyboard.next();
與
input = keyboard.next();
如果你在變量名之前放置一個String
,它就是一個聲明.而且你只能在一個范圍內聲明一個變量名.
If you put a String
before the variable name it is a declaration. And you can declare a variable name only once in a scope.
這篇關于Java 錯誤,重復的局部變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!