mlsb.net
当前位置:首页 >> jAvA 字母转换成数字 >>

jAvA 字母转换成数字

用ASCII码,A的ASCII码就是65,B的是66 public static void main(String[] args) { int i=1; char c=(char) (i+64); System.out.println(c); }

public class Test { public static void main(String[] args) { String str = "C002"; String shuzi = str.substring(1); char[] chars = str.toCharArray(); String new_str = chars[0]-64+shuzi; System.out.println(new_str); }}

其实字母其实是一个字符,而字符char类型本身其实存的是一个ASCII值,所以对于每一个字母的字符是有对应的一个数字 参考如下:

将字符转化成int型就可以了 public class Ex{ public static void main(String[] args){ for(char x='A';x

public class Change {//是这样吗public static void main(String[] args) {String inStr = "AB12D3Za#45";//qqgroup21/77/7/12StringBuffer outStr = new StringBuffer();for (int i = 0; i < inStr.length(); i++) {int c = (int)inStr.charAt...

java中String字符串转化为数字: 转换为浮点型: 使用Double或者Float的parseDouble或者parseFloat方法进行转换 String s = "123.456 "; //要确保字符串为一个数值,否则会出异常double d = Double.parseDouble(s); float f = Float.parseFloat(...

public static String wordToSignature(String word){ word = word.toLowerCase(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < word.length(); i++) { char c = word.charAt(i); if (c == 'a' || c == 'b' || c == 'c') { sb.a...

代码如下: public static void main(String[] args) { int i=1; int j=2; char c1=(char) (i+64); char c2=(char) (j+64); System.out.println(c1); System.out.println(c2); }

public class CharTest { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char ch =scanner.next().charAt(0); if ((ch >= 'a' && ch = 'A' && ch = '0' && ch

public static void main(String[] args) {String s = "Attitude";int sum = 0;s = s.toUpperCase(); //全部转换成大写for (int i = 0; i < s.length(); i++) {char c = s.charAt(i);sum += (int)c -64;}System.out.println(sum);}

网站首页 | 网站地图
All rights reserved Powered by www.mlsb.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com