public class zuoye
{
public static void main (String args[])
{ double n,sum=0.0;
for(int i=0;i<=args.length;i++)
{ sum=sum+Double.valueOf(args[i]).doubleValue();
}
n=sum/args.length;
System.out.println("平均数是:"+sum);
}
}
请高手帮我看看这段代码,为什么运行之后不能显示结果??
----------------解决方案--------------------------------------------------------
public class zuoye
{
public static void main (String args[])
{ double n,sum=0.0;
for(int i=0;i<=args.length;i++)//这里有问题会溢出 把那个= 去掉
{ sum=sum+Double.valueOf(args[i]).doubleValue();
}
n=sum/args.length;
System.out.println("平均数是:"+sum); //这里应该输出n
}
}
请高手帮我看看这段代码,为什么运行之后不能显示结果??这个题是关于命令提示符的阿 应该在cmd下面输入 java zuoye 5 6
譬如这样的 就可以了
----------------解决方案--------------------------------------------------------
楼住我也照你的方法做了 还是得不出结论啊
----------------解决方案--------------------------------------------------------
不可能得不出结论,只要你按照java zuoye 2 23 34 3
后面随便跟几个都可以,但是要空格格开各个数字
----------------解决方案--------------------------------------------------------
楼住我照着做了 能编译但运行的时候出现错误
Exception in thread main java.lange.ArrayzIndexzOutofBoundsException
----------------解决方案--------------------------------------------------------
不可能阿 =号你去了吗
----------------解决方案--------------------------------------------------------
是啊.没去=号 现在可以了.谢谢版住
版住帮我看个程序那里出问题了
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test5 extends JFrame implements WindowListener,ActionListener{
JLabel jl1=new JLabel("本金");
JLabel jl2=new JLabel("利率");
JLabel jl3=new JLabel("存款年数");
JLabel jl4=new JLabel("每年年金额总计");
JTextField jt1=new JTextField(10);
JTextField jt2=new JTextField(10);
JTextField jt3=new JTextField(10);
JTextArea ja1=new JTextArea(4,6);
JButton jbtnAdd=new JButton("计算");
//GridBagLayout gb;
;
/** Creates a new instance of Test5 */
public Test5(String s) {
super("s");
//GridBagLayout gd=new GridBagLayout();
Container jfrm=getContentPane();
//jfrm.setLayout(new GridLayout());
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(3,2));
JPanel p2=new JPanel();
p2.setLayout(new GridLayout(2,1));
p1.add(jl1);
p1.add(jt1);
p1.add(jl2);
p1.add(jt2);
p1.add(jl3);
p1.add(jt3);
jfrm.add(p1,BorderLayout.WEST);
p2.add(jl4);
p2.add(ja1);
jfrm.add(p2,BorderLayout.SOUTH);
jfrm.add(jbtnAdd,BorderLayout.EAST);
addWindowListener(this);
jbtnAdd.addActionListener(this);
}
public static void main(String[] args) {
Test5 t=new Test5("计算");
t.setSize(400,300);
t.setVisible(true);
}
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void actionPerformed(ActionEvent e) {
double sum=1,nu1,nu2,nu3;
nu1=(double)Integer.parseInt(jt1.getText());
nu2=(double)Integer.parseInt(jt2.getText());
nu3=(double)Integer.parseInt(jt3.getText());
sum=sum*nu1*(1.0f+nu2);
for(int i=1;i<Integer.parseInt(jt3.getText());i++)
sum=sum*(1.0f+nu2);
ja1.setText(String.valueOf(sum));
//getWrapStyleWord() 获取换行方式(如果文本区要换行)。
}
}
----------------解决方案--------------------------------------------------------
把你的问题说出来
----------------解决方案--------------------------------------------------------