• java代码----I/O流从控制台输入信息判断并抛出异常


    package com.a.b;
    
    import java.io.*;
    
    public class Yu {
    	public static void main(String[] args) throws IOException {
    		// InputStream is=new InputStream(System.in);
    		InputStreamReader isr = new InputStreamReader(System.in);
    		BufferedReader st = new BufferedReader(isr);
    		// 读取并输出字符串
    
    		System.out.println("请输入一个字符串:");
    		System.out.println(st.readLine());
    		boolean d = false;
    		do {
    			try {
    				System.out.println("请输入一个浮点数:----");// /注意这并不是一个循环,所以所有的数只能输入一次
    				double n = Double.parseDouble(st.readLine());
    				System.out.println(n);
    				d = false;// 这里是不会执行下一步了???是的,注释掉后,发现它会提示你永远输入浮点数,不会停止,那么判断起什么作用呢?
    			} catch (NumberFormatException E) {
    				System.out.println("数据无效,请重新输入:");
    				d = true;
    			}
    
    		} while (d);
    
    	}
    }
    

    总结:我一直以为是程序出了问题,因为输入有时候不正常,所以当把控制台上拉以后,一切都好了。所以相信手啊

  • 相关阅读:
    Python Semaphore
    Python 互斥锁
    Python 递归锁
    Python GIL锁
    Python 线程调用
    进程与线程
    Python paramiko模块
    Python SocketServer模块
    MonoDevelop with Visual Studio to Linux and Mac OSX maintaining a single code base for all platforms.
    mime大全收集
  • 原文地址:https://www.cnblogs.com/langlove/p/3485579.html
Copyright © 2020-2023  润新知