方法:程序不返回字符串
public String getRowsOf3Stars (int rows)
描述:
規定動作2)完成getRowsOf3Stars方法,該方法是 傳遞一個int(行)作爲參數。該方法返回一個字符串 ,其中包含該數量的三星級行。
例如,
getRowsOf3Stars(2) // returns 「***\n***\n」
如果行是小於1,則返回空字符串。 一個例子:
getRowsOf3Stars(2) // should return "***\n***\n"
我寫道:
public String getRowsOf3Stars (int rows) {
String getRowsOf3Stars="***\n";
if (rows<1){
String none="";
return none;
}
else{
for(int starRows=1;starRows<rows;starRows++){
return getRowsOf3Stars;
}
}
}
我上CodeWrite收到錯誤:
private String getRowsOf3Stars(int rows) throws Exception {
>> This method must return a result of type String
是否有人可以解釋爲什麼我的程序沒有返回一個字符串?