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

📄 keyin.java

📁 这是一个网友编写的文件分割程序
💻 JAVA
字号:

       /////////////////////////////////////////////////////////
       /////////KeyIn1.0此程序用于从控制台得到数据///////////////
       /////////////////////////////////////////////////////////
import java.io.*;

public class KeyIn
{
	
	public KeyIn(){KeyBoardInput = new BufferedReader
		 (new InputStreamReader(System.in));}
	//从控制台得到float类型的数据
	public float KeyInFloat(){
		try{
		    for(;;){
		    	Input = KeyBoardInput.readLine();
		    	char[]mychar=Input.toCharArray();
		    	for(int i=0;i<mychar.length;i++){
		    		ischar=Character.isDigit(mychar[i])||mychar[i]=='.';
		    		if(ischar==false){
		    			Input+="some chars are not digit";
		       			break;
		    		}
		    	}
		    	
		    	if(Input.length()>20||Input.equals("")){
		        	System.out.println("输入数据不合法");
		    	}
		    	
		    	else{		  
		       		Float floater = new Float(Input);
		    		theFloat=floater.floatValue();
		    		return theFloat;
		    	}
		    			
		  	 }	    
	    	}
		catch(IOException e){
			e.printStackTrace();
			return -1;
		}
	}
	//从控制台得到int类型的数据
	public int KeyInInt(){
		try{
		    for(;;){
		    	Input = KeyBoardInput.readLine();
		    	char[]mychar=Input.toCharArray();
		    	for(int i=0;i<mychar.length;i++){
		    		ischar=Character.isDigit(mychar[i]);
		    		if(ischar==false){
		    			Input+="some chars are not digit";
		       			break;
		    		}
		    	}
		    	
		    	if(Input.length()>10||Input.equals("")){
		        	System.out.println("输入数据不合法");
		    	}
		    	
		    	else{		  
		       		Integer integer = new Integer(Input);
		    		theInt=integer.intValue();
		    		return theInt;
		    	}
		    			
		  	 }	    
	    	}
		catch(IOException e){
			e.printStackTrace();
			return -1;
		}
	}
	public String KeyInString(){
		try{
			return KeyBoardInput.readLine();
		}
		catch(IOException e)
		{e.printStackTrace();return null;}
	}
	private BufferedReader KeyBoardInput;
	private String Input;
	private float theFloat;
    private boolean ischar;
    private int theInt;
    
}

⌨️ 快捷键说明

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