JAVA有没有直接提取读取数字的函数?(50分)

  • 主题发起人 主题发起人 qigpeng
  • 开始时间 开始时间
Q

qigpeng

Unregistered / Unconfirmed
GUEST, unregistred user!
我是一名新手,JAVA中有没有直接提取数字的函数并判断是否为数字,我提取出来的怎么老是不是那样的
int shu=0;
try
{
shu=System.in.read();
System.out.println("Enter a characater:" + shu);
}
catch(Exception e)
{
System.out.println("Canot read" + shu);
}
 
new Interger("10");
 
你要进行转化一下,读的不是int型的。
 
This question is bothering me too.
The number of reading is ASCII code of character from keyboard in.keyboard is a standard inputstream.
attending...
I'm learning java and english.So please correct my language error when correcting my program error.welcome exchanging.
 
int someInt = Integer.parseInt("123");
float someFloat = Float.parseFloat("12.34");
and etc.
 
shu=System.in.read();

if (Character.isDigit(shu))
Ok
 
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));
}
}

 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部