我自己写了个输入类,但有几个毛病解决不了,特向大家请教:
代码如下:import java.util.*;
import java.io.*;
class scanf //自定义输入法
{

static byte byte_8;
static int int_32;
static short short_16;
static long long_64;
static float float_32;
static double double_64;
static String string_str;
static char c;

static int int32()
{
Scanner sc = new Scanner(System.in);
int_32 = sc.nextInt();
return int_32;
}
static byte byte8()
{ Scanner sc = new Scanner(System.in);
byte_8 = sc.nextByte();
return byte_8;
}
static String str()
{
Scanner sc = new Scanner(System.in);
string_str = sc.nextLine();
return string_str;
}

static float float32()
{ Scanner sc = new Scanner(System.in);
float_32 = sc.nextFloat();
return float_32;
}
static double doulbe64()
{ Scanner sc = new Scanner(System.in);
double_64 = sc.nextDouble();
return double_64;
}
static short short16()
{ Scanner sc = new Scanner(System.in);
short_16 = sc.nextShort();
return short_16;
}
static char char_c()
{
        c = (char)System.in.read();
        return c;
}

}public class Test
{
public static void main(String [] args) throws IOException
{
int n;
n = scanf.int32();
System.out.println(n);
String str1 = scanf.str();
System.out.println(str1);
String str2 = scanf.str();
System.out.println(str2);
char c = scanf.char_c();
System.out.println(c);
}
}1 我不想每个方法里都实例化Scanner()类,因为这样感觉对内存开销增大很多(?),但是如果不这样,我就不能连续的输入,请问该怎办?
2 字符的 static char char_c()
{
        c = (char)System.in.read();
        return c;
}

输入这关我过不了.?
3 我想在每个return语句的前面加入类似C里的fflush(stdin);来清除掉缓冲区里的换行回车键对应的ASCII码,但不知道怎样来实现?