Default Style 註冊帳號
Games Animation Forum

不顯示圖片
手機資訊/電腦軟硬討論>java問題救命!! (超緊急,緊急,緊急)
毒雞ゲリョス 06:15 PM 01-05-03
我要寫一個 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
回覆
毒雞ゲリョス 08:29 PM 01-05-03
pls help me!!
回覆
t-cup 08:34 PM 01-05-03
第一:
寫個 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
回覆
毒雞ゲリョス 08:44 PM 01-05-03
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);
}
}
回覆
t-cup 09:04 PM 01-05-03
你自己睇有咩 error 先...

1st 要用 JOptionPane <- 但你唔 import package, 你點用?
2nd Applet 用 system.exit(0)? 感覺幾奇怪
3rd JOptionPane.showMessegeDialog(null, the number is"+ num1); <- 實有 compile error, 一望就知邊度出問題
回覆
毒雞ゲリョス 09:13 PM 01-05-03
我係初哥中的初哥所以我睇唔到錯乜,你可唔可以就呢個Applet 寫個code出來比我參詳一下??拜託請救救我!!
回覆
Shinji 09:28 PM 01-05-03
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^^
回覆
毒雞ゲリョス 09:38 PM 01-05-03
thank you, Shinji
but i don't know how to make computer know the number i enter is or is not a prime number it always show "the number is xx"
xx is the number i enter.
回覆
Shinji 10:22 PM 01-05-03
我的CONCEPT
PRIME是質數
質數只能被1或自己整除
咁…要試果個數係咪質數,
就要試下果個數比1或自己以外既數
除唔除得盡
個個數都除唔盡就係質數
是但一個除得盡就唔係質數
用FOR LOOP,BREAK; 運算子%,
IF…ELSE 黎自已砌下啦

其實茶杯老人兄果個METHOD我未用過,
亦都唔熟(係咪係MATH度拎架?)
佢果個實超方便
回覆
毒雞ゲリョス 10:36 PM 01-05-03
i know what u say but where i put the siauation?? pls tell me, thanks!請不要嫌我煩,我係咁問
回覆
Shinji 11:47 PM 01-05-03
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);
}
回覆
Shinji 11:50 PM 01-05-03
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...= =
回覆


返回主題版面