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);

	}
}

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

相关文章:

  • 2022-01-01
  • 2021-09-10
  • 2022-01-14
  • 2021-09-26
  • 2021-05-23
  • 2021-07-14
  • 2022-12-23
猜你喜欢
  • 2021-12-07
  • 2022-01-08
  • 2021-09-27
  • 2021-12-16
  • 2022-12-23
  • 2021-09-23
  • 2021-10-29
相关资源
相似解决方案