作者gh8811211 (媽!我上電視了)
看板java
標題[問題] 編譯有問題?
時間Tue Jul 27 14:20:54 2010
我按照書上程式照著輸入
檢查過沒有打錯字
編譯卻有錯誤
不知道問題出在哪
請高手幫我看看 謝謝
原程式如下:
import java.io.*;
import java.util.*;
public class MatchParenthesis
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in);
System.out.println("請輸入一段算式");
System.out.println("->");
String str = br.readLine();
LinkedList match = new LinkedLis();
for(int i=0; i<str.length(); i++)
if(str.charAt(i) == '(')
match.addFirst(new Charcter('('));
else if(str.charAt(i) == ')')
try
match.removeFirst();
catch(NoSuchElementException e)
{
System.out.print("左右括號數量不符, 右括號太少")
return;
}
if(match.isEmpty())
System.out.print("左右括號數量相符");
else
System.out.print("左右括號數量不符, 右括號太少")
}
}
使用javac MatchParenthesis.java 編譯
顯示以下錯誤:
Note: MatchParenthesis.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
使用javac MatchParenthesis.java -Xlint 編譯
出現以下錯誤:
MatchParenthesis.java:18: warning: [unchecked] unchecked call to addFirst(E)
as a member of the raw type java.util.LinkedList
match.addFirst(new Character('('));
^
1 warning
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.76.60.204
※ 編輯: gh8811211 來自: 211.76.60.204 (07/27 14:21)
※ 編輯: gh8811211 來自: 211.76.60.204 (07/27 14:22)
→ tkcn:1. 這是 warning 不是 error 2. 你的參考書太舊了 07/27 14:26
→ gh8811211:所以? 07/27 14:42
→ gh8811211:請問要改什麼地方呢 07/27 14:43
→ darkk6:Generic 07/27 14:52
→ gh8811211:不懂..所以我需要買一本新的書? 07/27 15:01
→ tkcn:你需要改的部份那本書上沒教,就這樣 07/27 15:04
→ sbrhsieh:main method 內第一行不是就錯了? 07/27 15:16