Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
public class control input type {
Static InputStreamReader in;
static BufferedReader reader;
Static
{in=new InputStreamReader (system.in);
Reader=new BufferedReader (in);
}
Control input is string
Static String readString ()
{String s= "";
Try
{S=reader.readline ();
}
catch (IOException E)
{System.out.println (e);
System.exit (0);
}
return s;
}
Control input is Char
static Char ReadChar ()
{char ch= ' a ';
Try
{
String s=readstring ();
Ch=s.charat (0);
}
catch (Exception e)
{System.out.println ("The input data type is incorrect, the program exits");
System.exit (0);
}
return ch;
}
control input is int
static int readInt ()
{String s=readstring ();
int i=0;
try{
I=integer.parseint (s);
}
catch (Exception e)
{System.out.println ("The input data type is incorrect, the program exits");
System.exit (0);
}
return i;
}
Control input is double
Static Double readdouble ()
{String s=readstring ();
Double d=0.0;
Try
{d=double.parsedouble (s);
}
catch (Exception e)
{System.out.println ("The input data type is incorrect, the program exits");
System.exit (0);
}
return D;
}
Control input is float
static float Readfloat ()
{
String s=readstring ();
float f=0.0f;
Try
{
F=float.parsefloat (s);
}
catch (Exception e)
{System.out.println ("The input data type is incorrect, the program exits");
System.exit (0);
}
return F;
}
}
Java limit console input type of value