Re: [考題] 102高考資料處理 Java

看板Examination作者 (媽媽咪阿)時間12年前 (2013/07/18 11:19), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/3 (看更多)
: 三、請問執行下列JAVA 程式碼後的結果為何?請繪製此程式的流程圖。(20 分) : 01. public class ShowClass { : 02. public static void main( String[] args ) : 03. { : 04. int row = 4; : 05. int column; : 06. : 07. while ( row >= 1 ) : 08. { : 09. column = 1; : 10. : 11. while ( column <= 5 ) : 12. { : 13. System.out.print( row % 2 == 1 ? "<-" : "->" ); : 14. ++column; : 15. } // end while : 16. : 17. --row; : 18. System.out.println(); : 19. } // end while : 20. } // end main : 補習班公佈的流程圖不才是看得懂,而補習班的輸出結果為: : ->->->->-> : <-<-<-<-<- : ->->->->-> : <-<-<-<-<- : 因為本身非資訊背景,所以想請教各位程式的 : 13. System.out.print( row % 2 == 1 ? "<-" : "->" ); : 列2是否等於1?甚麼意思? row是第4行宣告的變數(值為4) row%2==1表示4(變數row)除以2的餘數是否為1, 是就是問號(?)後面第一項("<-"),否的話就是第二項("->") : 14. ++column; : 它跟C語言的前置模式的用法是一樣的嗎? 是的~~一樣 : 17. --row; : 原因同上 也一樣~ 小弟本身也不強~希望這樣回答能幫助到你~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.242.194.16

07/18 12:22, , 1F
豬仔好棒!
07/18 12:22, 1F

07/18 13:36, , 2F
樓上過獎了...小弟很弱的~話說樓上認識小弟?
07/18 13:36, 2F
文章代碼(AID): #1HvrxCed (Examination)
文章代碼(AID): #1HvrxCed (Examination)