![]() |
|
![]() |
#1 |
Junior Member
![]() 註冊日期: May 2002
文章: 68
|
java問題救命!! (超緊急,緊急,緊急)
我要寫一個 java Applet,叫人入一個正整數,跟往部機會show messege this is a prime or not a prime number,可唔可以show d step出來教我點做??
thank you everyone!! p.s i am a newer of java 此篇文章於 01-05-03 06:47 PM 被 瘥ゲリョス 編輯。 |
![]() |
![]() |
![]() |
#3 |
Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 註冊日期: Dec 2001
文章: 17,046
![]() ![]() ![]() |
第一:
寫個 frame extends JApplet 第二: 之後可以o向裡面加一個 text field and 一個 button 第三: o向個 button 度加 actionlistener, keep check "click" 第四: code 計 prime nos. 的 method, o向步三果度去 call 哩個 method 第五: applet 某個位 (text field or label) display 番個 value
__________________
とびだせ どうぶつの森 夢番地: 3500-0401-8131 UNICEF, help the children in needs 3DS: 4511-1485-9506, XBOX360: tcuphk, PS3: tcuphk2, PSVITA: tcuphk |
![]() |
![]() |
![]() |
#4 |
Junior Member
![]() 註冊日期: May 2002
文章: 68
|
very difficult....
here is my code, but can't compile... and i don't know how to do..... can u help me to correct it and post the code,thank you very much import java.awt.Graphics; import javax.swing.JApplet; public class c extends JApplet { String one; one=JOptionPane.showInputDialog("Enter a Positive Integer") int num1; num1=Integer.parseInt(one); JOptionPane.showMessegeDialog(null, the number is"+ num1); System.exit(0); } } |
![]() |
![]() |
![]() |
#5 |
Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 註冊日期: Dec 2001
文章: 17,046
![]() ![]() ![]() |
你自己睇有咩 error 先...
1st 要用 JOptionPane <- 但你唔 import package, 你點用? 2nd Applet 用 system.exit(0)? 感覺幾奇怪 3rd JOptionPane.showMessegeDialog(null, the number is"+ num1); <- 實有 compile error, 一望就知邊度出問題
__________________
とびだせ どうぶつの森 夢番地: 3500-0401-8131 UNICEF, help the children in needs 3DS: 4511-1485-9506, XBOX360: tcuphk, PS3: tcuphk2, PSVITA: tcuphk |
![]() |
![]() |
![]() |
#7 |
Senior Gamer
![]() ![]() 註冊日期: Oct 2002
文章: 178
|
import java.awt.Graphics;
import javax.swing.*; public class test extends JApplet { public void init() {String one; one=JOptionPane.showInputDialog("Enter a Positive Integer"); int num1; num1=Integer.parseInt(one); JOptionPane.showMessageDialog(null, "the number is"+ num1,"Result",JOptionPane.INFORMATION_MESSAGE); } } //同你整晒上面D SYTAX ERRORS… //USE APPLETVIEWER TO VIEW //THE PROGRAMMING STYLE MAYBE NOT GOOD //U FINISH THE PRIME PART BY YOURSELF^^
__________________
轉型純愛中...- -+ |
![]() |
![]() |
![]() |
#9 |
Senior Gamer
![]() ![]() 註冊日期: Oct 2002
文章: 178
|
我的CONCEPT
PRIME是質數 質數只能被1或自己整除 咁…要試果個數係咪質數, 就要試下果個數比1或自己以外既數 除唔除得盡 個個數都除唔盡就係質數 是但一個除得盡就唔係質數 用FOR LOOP,BREAK; 運算子%, IF…ELSE 黎自已砌下啦 其實茶杯老人兄果個METHOD我未用過, 亦都唔熟(係咪係MATH度拎架?) 佢果個實超方便
__________________
轉型純愛中...- -+ |
![]() |
![]() |
![]() |
#11 |
Senior Gamer
![]() ![]() 註冊日期: Oct 2002
文章: 178
|
if(num1>2){
for(int i=2;i<num1;i++) { if(num1%i==0){ JOptionPane.showMessageDialog(null, num1+"is NOT the PRIME number ","Result",JOptionPane.INFORMATION_MESSAGE); break; } else if(i==(num1-1)){ JOptionPane.showMessageDialog(null, num1+"is the PRIME number is","Result",JOptionPane.INFORMATION_MESSAGE); } } } else if((num1==1)||(num1==2)){ JOptionPane.showMessageDialog(null, num1+"is the PRIME number ","Result",JOptionPane.INFORMATION_MESSAGE); } else if(num1<1){ JOptionPane.showMessageDialog(null, num1+"is out of scope.","Result",JOptionPane.INFORMATION_MESSAGE); }
__________________
轉型純愛中...- -+ 此篇文章於 01-05-03 11:56 PM 被 Shinji 編輯。 |
![]() |
![]() |
![]() |
#12 |
Senior Gamer
![]() ![]() 註冊日期: Oct 2002
文章: 178
|
OOPS
I FOUND THAT THERE HAS SOME CODE CAN"T OUT MAYBE THE 表情符號 I UPLOADED LA http://e-ocean.netfirms.com/test.java OR U QUOTE MY TEXT TO SEE LA = = THAT WEBSPACE ADDED OR REPLACE SOMETHING TO MY JAVA...= =
__________________
轉型純愛中...- -+ 此篇文章於 01-06-03 12:04 AM 被 Shinji 編輯。 |
![]() |
![]() |