ch7ex5.java

来自「JAVA程序设计 丁岳伟 彭敦陆编 高等教育出版社 第7---11章程序」· Java 代码 · 共 31 行

JAVA
31
字号
import java.util.*;
public class ch7ex5{
	public static void main(String[]args){
		double d[]=new double[5];
		System.out.println("Input a list:");
		String str=Keyboard.readString();
		StringTokenizer dte=new StringTokenizer(str);
		boolean indexError=false;
		int ind=0;
		while(dte.hasMoreTokens()&&!indexError){
			String s=dte.nextToken();
			try{
				d[ind]=Double.parseDouble(s);
				ind++;
			}catch(NumberFormatException e1){
				System.out.println(e1.getMessage());
			}catch(IndexOutOfBoundsException e2){
				indexError=true;
			}
		}
		if(indexError)
			System.out.println("There are more than 5 string on the list");
		else{
			System.out.println("Number of valid string: "+ind);
			for(int j=0;j<ind;j++)
				System.out.print(d[j]+" , ");
			System.out.println();
		}
	}
}
				

⌨️ 快捷键说明

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