任何人都可以告訴我爲什麼我的最後一個返回語句不起作用嗎?返回聲明錯誤 - 解析IP地址字符串
public class IpAddress
{
private String dottedDecimal;
private int[] Octet= new int[4];
public int i;
//Default constructor
public IpAddress()
{
dottedDecimal = "0.0.0.0";
for (i=0; i<=3; i++)
{
Octet[i] = 0; //setting the array to zero
}
} // end default constructor
//************************************
//Specified constructor
public IpAddress(String myAddress)
{
dottedDecimal = myAddress;
String[] parsedOctets;
parsedOctets = myAddress.split("\\Q.\\E"); // allows to stop at the dot
for (i=0; i <=3; i++)
{
Octet[i] = Integer.parseInt(parsedOctets[i]); // breaking the string down to integers
}
}// end specified constructor
//*****************************************************
public String getDottedDecimal()
{
return dottedDecimal;
}
//*********************
public int getOctet()
{
for (this.i=0; this.i <=3; this.i++)
{
return this.Octet[i];
}
}
} // end ip address class
你是什麼意思「las return statement」?請提供更多詳細信息... – 2009-10-23 01:15:29
不要忘記單擊複選標記以接受答案... – 2009-10-23 02:29:07
Bob Kaufman已發佈解決方案。但我想我會評論一下事情。 「我」不應該是一個實例變量。應該使用實例變量來存儲對象的狀態。我是一個用於迭代方法的計數器。它與對象本身無關。相反,你應該這樣做:「for(int i = 0; i <= 3; i ++){...}」。 這種方式很明顯,「我」是專門爲迭代for循環而創建的。不,它不需要更多的資源。事實上,它需要少得多。 – 2009-10-23 12:13:16