如题。谢谢各位!~
解决方案 »
- 使用Eclipse怎样将编译好的class文件清理掉?
- 我想把对象存成文件,然后在压缩成zip.然后在解开这个zip还原对象。但是总是失败。有原代码。希望知道的大侠帮忙看看啊。。。。。。。。谢谢了啊
- 怎么得到System.out.println的内容
- jsp传递中文参数乱码问题
- 一个关于排列组合的问题
- 如何消除一个panel上所有的控件?
- 在线等:一个TreeMap类,想实现先put的东西排序在前,该怎么实现Comparator接口啊
- 急救线程!!!
- 为什么JTextArea和JTextPane控件在appplet中不能连贴来自外部的复制?
- layout用null好像很舒服
- 三目条件运算符的一个使用问题???
- 求救啊!关于JACOB项目,100分^_^!
Pattern p=Pattern.compile("^0|(-?[1-9]\\d*$");//这是整数的正则表达式
String s="12343";
if(p.matcher(s).matches()){//整数
BigInteger b=new BigInteger(s);
if(b.compareTo(new BigInteger(Integer.MIN_VALUE)>0&&
b.compareTo(new BigInteger(Integer.MAX_VALUE)){//在int的范围内
int k=b.intValue();//得到这个整数
}
}double同上,正则表达式为^0|(\\x2E\\d+)|([+-]?0\\x2E\\d+)|([+-]?[1-9]\\d*(\\x2E\\d+)?)$
{
Pattern p = Pattern
.compile("^0|(\\x2E\\d+)|([+-]?0\\x2E\\d+)|([+-]?[1-9]\\d*(\\x2E\\d+)?)$");
if (p.matcher(s).matches())
{
BigInteger b = new BigInteger(s);
a = b.compareTo(new BigInteger(String.valueOf(Double.MIN_VALUE))) > 0
&& b.compareTo(new BigInteger(String.valueOf(Double.MAX_VALUE))) < 0;
}
Integer变成Double就不行了,但是变成Long又可以了,这是怎么回事啊?谢谢? return a;
}
public static boolean isInteger(String sample){
char[] charArray=sample.toCharArray();
int index=0;
if(charArray[0]=='-')
index=1;
for(;index<charArray.length;index++)
if(!Character.isDigit(charArray[index]))
return false;
return true;
}
public static boolean isFloat(String sample){
int dot=0;
char[] charArray=sample.toCharArray();
int index=0;
if(charArray[0]=='-')
index=1;
for(;index<charArray.length;index++){
if(!Character.isDigit(charArray[index])&&charArray[index]!='.'){
return false;
}
if(charArray[index]=='.')
dot++;
}
if(dot<2)
return true;
else
return false;
}
public static void main(String[] args){
String sample="-123";
if(StringIdentifier.isInteger(sample))
System.out.println(Integer.valueOf(sample));
else
System.out.println("cannot cast \""+sample+"\" into an Integer");
if(StringIdentifier.isFloat(sample))
System.out.println(Float.valueOf(sample));
else
System.out.println("cannot cast \""+sample+"\" into a Float");
}
}
千万别用异常判断,会影响JVM运行效率(参见Effective Java)。