import java.io.*;
import java.lang.*;
public class Propogate1
{
String reverse(String name)
{
if(name.length()==0)
throw IOException("name");
String reverseStr="";
for(int i=name.length()-1;i>0;--i)
{
reverseStr+=name.charAt(i);
}
return reverseStr;
}
public static void main(String[] args)throws IOException
{
String name;
try
{
Propogate1 p=new Propogate1();
p.reverse("java");
}
finally
{
System.out.println("done");
}
}
}
我必須創建一個類propogate和main方法,它將調用reverse()。在這種情況下,如果name.length爲null,它將引發異常。如果它不爲null,它將反轉字符串。請幫助我錯誤在下面的代碼附近拋出IOException
導入時,你不應該使用通配符包年齡。總是(在可以使用通配符時出現一些罕見情況)使用包名稱+要導入的類名稱(例如import java.io.IOException)。否則,您可能在使用不同的軟件包時出現相同的類名稱 – Dennis 2010-10-18 05:56:47
也存在一些問題您的* for *循環中存在一個錯誤,在您遵循@ Guillaume的答案後需要修復 – JoseK 2010-10-18 05:59:09
@JoseK:我已經刪除了「for循環錯誤」太 – ivorykoder 2010-10-18 06:17:52