![]() |
PCDVD數位科技討論區
(https://www.pcdvd.com.tw/index.php)
- 七嘴八舌異言堂
(https://www.pcdvd.com.tw/forumdisplay.php?f=12)
- - 問一個JAVA小問題~急需幫忙...!
(https://www.pcdvd.com.tw/showthread.php?t=548345)
|
|---|
樓主,你唸那啊?這跟我上學期做到的題目簡直一模一樣...
我要找一下有沒有把這個檔存著... |
改八樓大大的程式= = 應該是你要的吧
順便一提,是我神人同學改的 XD.... class A { public static void main(String args[]) { int Xstart = 0, Xend = 0; for(int i = 1; i < 10; i++) { Xstart = Math.abs( 5 - i ) + 1; Xend = 9 - ( Xstart - 1 ); for(int j = 1; j < 10; j++) { if( j < Xstart || j > Xend ) System.out.print(" "); else { for(int k = 1; k <= Xend - Xstart + 1; k++) { System.out.print("*"); } j = Xend; } } System.out.println(""); } } } |
引用:
上面那個解答也是答案不是嗎? 而且還是最快的....連想都不用想 難道寫程式一定要有標準答案? :cool: 能夠解決問題才是重點,只是差在方法的好與不好罷了。 |
去年寫的... :shy:
主程式108行... :unbelief: (阿..忘記放sourcecode進去了..晚點補...orz) |
代碼:
public static void main(String[] args)
{
String strStars = "*";
String strSpaces = " ";
int i, j;
int nRow = 64;
for (i = 0; i <= Math.log(nRow + 2) / Math.log(2); i++)
{
strStars += strStars;
strSpaces += strSpaces;
}
for (i = 0, j = 0; i < nRow; i++)
{
System.out.print(strSpaces.substring(0, (nRow - 1) / 2 - j));
System.out.println(strStars.substring(0, (j * 2 + 1)));
if (nRow < (i * 2 + 2))
j--;
else if (nRow > (i * 2 + 2))
j++;
}
}
|
原来java那么麻烦啊
看来c简单多了 |
引用:
小弟也這麼認為,且在討論執行速度上,可是最快的. |
引用:
話是這麼說沒錯...但是感覺沒啥創意不是嗎... :rolleyes: 難怪台灣的軟體業比別國差一些.... :stupefy: (肯思考創新的人很少...公司也是...) 話說那時為了增加這玩意的功能我寫了快一個禮拜....(一天改一點... ;) ) 不過寫好有爽到... :hungry: 雖然只是寫好玩的... :ase |
引用:
用C#來寫會更簡單 :) 代碼:
static void Main(string[] args)
{
int i, j, nRow = 30;;
for (i = 0, j = 0; i < nRow; i++, j += Math.Sign(nRow - i * 2))
{
Console.WriteLine(String.Empty.PadRight(j * 2 + 1, '*').PadLeft((nRow + 1) / 2 + j, ' '));
}
}
|
沒辦法
java大概要自己寫好api吧 哀哀哀 連stored procedure 都還比較好用 |
| 所有的時間均為GMT +8。 現在的時間是05:38 AM. |
vBulletin Version 3.0.1
powered_by_vbulletin 2026。