package com.hqy.io;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.omg.CORBA.PUBLIC_MEMBER;
public class JavaIo {
public static String getString() throws IOException {
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
return s;
}
//先读入一个字符串,再通过charAt()方法摘取他的第一个字符,可以有效防止 多读入一个(错误)字符,导致错误.
public static char getChar() throws IOException {
String string=getString();
return string.charAt(0);
}
public static int getInt() throws IOException{
String string=getString();
return Integer.parseInt(string);
}
public static double getDouble() throws IOException{
String string=getString();
Double a=Double.valueOf(string);
return a.doubleValue();
}
public static float getFloat() throws IOException {
String string=getString();
Float float1=Float.valueOf(string);
return float1.valueOf(float1);
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.out.println("请输入字符串:");
System.out.println(getString());
System.out.println("请输入字符:");
System.out.println(getChar());
System.out.println("请输入整数:");
System.out.println(getInt());
System.out.println("请输入双精度浮点数:");
System.out.println(getDouble());
System.out.println("请输入单精度浮点数:");
System.out.println(getFloat());
}
}
java字符串、字符、整数、浮点数输入方式笔记
最新推荐文章于 2021-08-21 17:28:53 发布