一个java小程序 达人给看下

来源:百度知道 编辑:UC知道 时间:2024/06/22 10:32:36
package test1;
import javax.swing.*;
import java.util.StringTokenizer;
public class Test2 {
public static void main(String[] args) {
// TODO 自动生成方法存根
StringTokenizer st;
String input;
int[] array;
boolean go;
do{
go=false;
input="";
input=JOptionPane.showInputDialog("请输入你要进行排序的数字");
st = new StringTokenizer(input," ,_-",false);
array=new int[st.countTokens() ];
for(int i=0;i<array.length;i++)
try{
array[i]=Integer.parseInt(st.nextToken());
}
catch (Exception e) {
//JOptionPane.showMessageDialog(null, "请输入一组整数 数字之间用空格或逗号间隔", "错误", JOptionPane.WARNING_MESSAGE);
go=true;
//System.exit(0);
if(go)
JOptionPane.showMessageDialog(null, "请输入一组整数 数字之间用空格或逗号间隔", "错误", JOptionPane.WARNING_MESSAGE);
}
}while(go);
Image

import javax.swing.*;
  import java.util.StringTokenizer;

  public class Test2
  {
  public static void main(String[] args)
  {
  // TODO 自动生成方法存根
  StringTokenizer st;
  String input;
  int[] array;
  boolean go;
  do
  {
  go = false;
  input = "";
  input = JOptionPane.showInputDialog("请输入你要进行排序的数字");
  st = new StringTokenizer(input, " ,_-", false);
  array = new int[st.countTokens()];
  for (int i = 0; i < array.length; i++)
  {
  try
  {
  array[i] = Integer.parseInt(st.nextToken());
  }
  catch (Exception e)
  {
  go = true;
  JOptionPane.showMessageDialog(null,
  "请输入一组整数 数字之间用空格或逗号间隔", "错误",
  JOptionPane.WARNING_MESSAGE);
  break;
  }
  }
  }
  while (go);
  ImageIcon img = new ImageIcon(
  "C:/Documents and Settings/Administrator/桌面