⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convert.java

📁 包括了5个基本排序过程
💻 JAVA
字号:
//实现数据串文本与一维数组的转换
public class Convert 
{
	private static String str;
	private static double[] array;
	public Convert()
	{
	}
	public static String arraytostring(double [] arraytem)//实现数组到字符串的转换
	{
		str="";//这句很重要 不然界面类里的text2会积累显示。因为str是一个静态的变量
		for(int i=0;i<arraytem.length;i++)
		{
			str=str+Double.toString(arraytem[i])+" ";
		}
		return str;
	}
	public static double[] stringtoarray(String strtem)//实现字符串到数组的转换
	{
		array=null;
		try
		{
			strtem=strtem.trim();
			if(strtem.length()<=0) throw new NumberFormatException();
			double [] temp=new double[50];
			int j=0;
			for(;strtem.length()>0;j++)
			{
				if(strtem.indexOf(" ")>0)
					{
						temp[j]=Double.parseDouble(strtem.substring(0, strtem.indexOf(" ")));
						strtem=(strtem.substring(strtem.indexOf(" "))).trim();
					}
				else {
						temp[j]=Double.parseDouble(strtem.substring(0));
						strtem="";
						break;
					}
			}
			//此时temp中有j+1个double数据
			array=new double[j+1];
			for(int i=0;i<=j;i++)
			{
				array[i]=temp[i];
			}
		}
		catch (NumberFormatException e)
		{
			/*System.out.println(
            "Your input number is not correct.");
			System.out.println(
            "Your input number must be");
			System.out.println(
             "an ordinary number either with");
			System.out.println(
              "or without a decimal point,");
			System.out.println("such as 42 or 9.99");
			System.out.println("Please try again.");*/
			//MessageBox Blank=new MessageBox("警告","请正确的输入需要排列的数字");
			//Blank.setVisible(true);
			
		}
		catch(NullPointerException e2)
		{
			//MessageBox Blank=new MessageBox("警告","请正确的输入需要排列的数字");
			//Blank.setVisible(true);
		}
		return array;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -