程序應該使用嵌套for循環輸出以下內容,如果可能,最好不要使用pow()
方法。任何幫助或建議被appreciated.Expected結果:權力表
1 1 1 1 1 1
2 4 8 16 32 64
3 9 27 81 243 729
4 16 64 256 1024 4096
我嘗試它:
class TableOfPowers
{
public static void main(String [] args)
{
int startValue = 1;
int y = 1;
for (int row =0; row < 4; row++)
{
for (int col = startValue; col < startValue+6; col ++)
{
y = y *startValue;
System.out.print(y + " ");
}
System.out.println();
startValue++;
}
}
}
問題是什麼?請具體說明。 – rgettman
你期待什麼結果? – Perdomoff
這是一項研究任務嗎?它看起來像是在作業或測試中的問題。 – mwotton