resolve it as 曹晓钢 saying.
/**I have master the methods of reading number from consle,
*but Ido
n't know if it exists a more simple method todo
it,like we
*cando
in C or BASIC.
*/
//package testreadnumber;
public class TestReadNumber {
public static void main(String[] args)throws Exception {
StringBuffer sB = new StringBuffer();
String s = null;
char c = 0;
float data = 0;
int intData = 0;
do
uble dData = 0;
//read number in running.
while (true){
c = (char)System.in.read();
if (c != 13)
sB.append(c);
else
break;
}
s = sB.toString();
data = Float.parseFloat(s);
System.out.println("square(data) is: " + Math.pow(data, 2));
//read number from arguments list of main()
if(args.length > 0) {
intData = Integer.parseInt(args[0]);
dData =do
uble.parseDouble(args[1]);
//...
}
System.out.println("square(intData) is: " + Math.pow(intData, 2));
System.out.println("square(dData) is: " + Math.pow(dData, 2));
}
}