我是靠谱客的博主 生动黄蜂,这篇文章主要介绍JAVA字符串转化为数字(可以适合大部分),现在分享给大家,希望可以做个参考。



package test;



import java.io.IOException;
import java.util.Scanner;


public class StringTranportNum {
   
public static int StrToInt(String S){
int number=0;
int i=0;
String num="";
char k[]=S.toCharArray();
while(k.length>i){
num=num+(k[i++]-'0');
}
number=Integer.parseInt(num);

return number;
}

public static String Input(){
String S;
System.out.println("请输入你需要转化的字符串:");
Scanner in=new Scanner(System.in);
S=in.nextLine();
return S;
}

public static void main(String args[]) throws IOException{
String s=Input();
while(s.length()==0)//如果输入字符串为回车则再次输入
s=Input();
System.out.println(new StringTranportNum().StrToInt(s));
}
}

最后

以上就是生动黄蜂最近收集整理的关于JAVA字符串转化为数字(可以适合大部分)的全部内容,更多相关JAVA字符串转化为数字(可以适合大部分)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部