String类型转int类型
来源:互联网 发布:sql 索引超出数组界限 编辑:程序博客网 时间:2024/05/18 01:43
public class MyAlgTest {
public static int atoi(String str){
if(str == null || str.length() < 1){
return 0;
}
str = str.trim();
char flag = '+';
int i = 0;
if(str.charAt(0) == '-'){
flag = '-';
i++;
}else if(str.charAt(0) == '+'){
i++;
}
double result = 0;
while(str.length() > i && str.charAt(i) >= '0' && str.charAt(i) <= '9'){
result = result * 10 + (str.charAt(i) - '0');
i++;
}
if(flag == '-'){
result = -result;
}
if(result > Integer.MAX_VALUE){
return Integer.MAX_VALUE;
}
if(result < Integer.MIN_VALUE){
return Integer.MIN_VALUE;
}
return (int)result;
}
}
public static int atoi(String str){
if(str == null || str.length() < 1){
return 0;
}
str = str.trim();
char flag = '+';
int i = 0;
if(str.charAt(0) == '-'){
flag = '-';
i++;
}else if(str.charAt(0) == '+'){
i++;
}
double result = 0;
while(str.length() > i && str.charAt(i) >= '0' && str.charAt(i) <= '9'){
result = result * 10 + (str.charAt(i) - '0');
i++;
}
if(flag == '-'){
result = -result;
}
if(result > Integer.MAX_VALUE){
return Integer.MAX_VALUE;
}
if(result < Integer.MIN_VALUE){
return Integer.MIN_VALUE;
}
return (int)result;
}
}
0 0
- String类型转int类型
- Grails string转int类型
- int转string、wstring类型
- java String转Int类型
- String 类型 转为 Int 类型
- string类型转换int类型
- string类型转换int类型
- java中int转String类型,String类型转int类型
- c++ string转int,int 转string,类型转换
- string转换成int类型 和int转string
- CString用法,转String,转int类型
- 将int/double 转string类型
- [转]string, char*, int类型转换
- 【转】string, char*, int类型转换
- Android String与int类型互转
- Java-int与string类型互转
- JAVA 中int类型转String类型的通常方法
- Integer类型、int类型类型、String类型的相互转换
- leetcode第一刷_Best Time to Buy and Sell Stock
- 《Essential C++》 基础知识
- 题目1018:统计同成绩学生人数
- hdu 1598 find the most comfortable road
- 二维码生成器-客户端
- String类型转int类型
- p3p sso
- Eclipse学习和错误总结
- 查看反汇编代码
- 设计模式系列课程08之【开闭原则】
- 在File中存储和读写文字
- 解决TabActivity 与 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)的冲突
- 题目1031:xxx定律
- CRC校验算法的解析,暨对网上的CRC详解的补充