[操作疑難] java 質數問題

Write a program that inputs an integer value from user. The value is then
passed to method isPrime() which returns true if the value is a prime number and
false otherwise. The result is printed on screen. Example executions are shown below.
c:\exercise> java CheckPrime
Number? 7
Prime number
c:\exercise> java CheckPrime
Number? 9
Not a prime number

Remember: isPrime() only checks and returns the result (true or false). The result
is printed by main().

唔識搞
要用RETURN... 搞左成晚都唔識
有冇Ching幫手

Write a program that inputs an integer value from user. The value is then
passed to method isPrime() ...
louis10022hk 發表於 2011-10-5 01:55


不如你諗下,如果要你人手計你會點做...

TOP

不如你諗下,如果要你人手計你會點做...
insanity 發表於 2011-10-5 01:56



    睇下佢係咪得自己同一先除到
不斷加一去試

TOP

yes,如果有個數除得盡即係唔係質數,咪return false囉
試到個數o既一半都係除唔盡,咁咪除過晒,即係係質數囉

TOP

yes,如果有個數除得盡即係唔係質數,咪return false囉
試到個數o既一半都係除唔盡,咁咪除過晒,即係係質 ...
insanity 發表於 2011-10-5 02:01



    其實我唔係好明點打CODE先出到..."Prime number"咁樣
用ECLIPSE 成日出紅線
System.out.println("Prime Number");

TOP

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

TOP

咁低解像度點睇

TOP

樓主參考下呢位ching既code,
將if果part refactor做一個method~
http://www.hkepc.com/forum/viewt ... &extra=page%3D2

TOP