日期:2014-05-20  浏览次数:20788 次

急求一个小程序
急求一个小程序:
要求输入一个一百位以上的数字n,求n的e次方再除以d的余数
其中n可以用随机数获取(输入一个种子),e和d是自己输入的数字

有界面的再送100分
界面至少有三个框框,分别输入三个数,有一个按钮用来求值



------解决方案--------------------
public class math2 {
private double n;
private double e;
private double d;

public math2(String str1,String str2,String str3)
{

n=Double.parseDouble(str1);
e=Double.parseDouble(str2);
d=Double.parseDouble(str3);
}
/*
public double get_n()
{
return(this.n);
}
public double get_e()
{
return(this.e);
}
public double get_d()
{
return(this.d);
}
*/
public double act()
{
double r=Math.pow(n,e);
System.out.print(d);
r=r%d;
return(r);


}

public static void main(String [] args)
{
String str1 = JOptionPane.showInputDialog( "enter n: ");
String str2=JOptionPane.showInputDialog( "enter e: ");
String str3=JOptionPane.showInputDialog( "enter d: ");
math2 m=new math2(str1,str2,str3);
double r;
r=m.act();
JOptionPane.showMessageDialog(null, "the result is "+r, "result ",JOptionPane.INFORMATION_MESSAGE);

}


}
不理解你的意思 大概写了一下 LZ参考一下好了
------解决方案--------------------
import java.awt.GridLayout;

public class ModeCalculate extends java.awt.Dialog {

public ModeCalculate(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}

private void initComponents() {
label11 = new java.awt.Label();
textN = new java.awt.TextField();
label12 = new java.awt.Label();
textE = new java.awt.TextField();
label13 = new java.awt.Label();
textD = new java.awt.TextField();
button = new java.awt.Button();
label14 = new java.awt.Label();

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
label11.setText( "输入n: ");
label12.setText( "输入e: ");
label13.setText( "输入d: ");
button.setLabel( "计算 ");
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button3ActionPerformed(evt);
}
});

label14.setText( " ");
this.setLayout(new GridLayout(4, 2));
this.add(label11);
this.add(textN);
this.add(label12);
this.add(textE);
this.add(label13);
this.add(textD);
this.add(button);
this.add(label14);
this.setSize(500,600);
pack();
}

private void button3ActionPerformed(java.awt.event.ActionEvent evt) {
label14.setText( " ");
long n = Long.parseLong(textN.getText());
long d = Long.parseLong(textD.getText());
long e = Long.parseLong(textE.getText());
label14.setText( " "+calculate(n, d, e));
}

private long calculate(long n, long d, long e) {
if (e == 1)
return n%d;
return (n*calculate(n, d, e-1))%d;