java 小程序 麻烦看一下有什么问题

来源:百度知道 编辑:UC知道 时间:2024/05/18 01:01:58
import javax.swing.JOptionPane;

public class DisplayTime{
public static void main(String[] args){
int seconds=500;
int minutes=seconds/60;
int remainingSeconds=seconds%60;
JOptionPane.showMessageDialog(null,seconds+" second is "+minutes+" minutes and "+remainingSeconds +" seconds");
JOptionPane.showMessageDialog(null,"u6B22\u8FCE \u03b1 \u03b2 \u03b3","u6B22\u8FCE welcome",JOptionPane.INFORMATION_MESSAGE);
System.out.println("The temperature is "+args[0]+ "aa" +args[1]);
}
}

运行的时候应该传入参数 java DisplayTime 60 60

import javax.swing.JOptionPane;
class MyFirstClass{

public static void main(String[] args){
int seconds=500;
int minutes=seconds/60;
int remainingSeconds=seconds%60;
JOptionPane.showMessageDialog(null,seconds+" second is "+minutes+" minutes and "+remainingSeconds +" seconds");
JOptionPane.showMessageDialog(null,"u6B22\u8FCE \u03b1 \u03b2 \u03b3","u6B22\u8FCE welcome",JOptionPane.INFORMATION_MESSAGE);
System.out.println("The temperature is "+args[0]+ "aa" +args[1]);
}

}

异常为:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at MyFirstClass.main(MyFirstClass.java:12)

System.out.println("The temperature is "+args[0]+ "aa" +args[1]);
这一句去掉,这一句没实际意义,在你运行的时候不传入两个以上的参数就会抛数组越界的异常。

挺好的,没什么问题<