如何取得一个字符串的最后一个字母? String s ="ABCDEFG";String result = s.substring(s.length()-1); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String s = "ABCDEFG"char c = s.charAt(s.length() - 1); char last = null; String s = "ABCDEFG" last = s.charAt(s.length() - 1); String temp="ABCDEFG";temp=temp.substring(temp.length()-1,temp.length());so that temp is "G" String s = 输入的字符串;char last;if (s != null){ last = s.charAt(s.length() -1);} 需要-1吗?如果是5位的数字,那substring()中取第5位数字不就是最后一位了,干吗还要-1呢? java和c,c++一样,数组的下标是从0开始 唉~~自己用substring试一试不就知道了么?动动手吧 从上面的答案可以看出问题:chatAt才是正解,返回的是charsubString返回的是String String s = 输入的字符串;char last;if (s != null){ last = s.charAt(s.length() -1);} swith(ch)中的ch 为什么要定义成 int 类型? 字符串操作 关于自增运算优先级的问题,请赐教! 寻求JAVA高等数学公式算法 关于java生成对象的一点疑惑,请教大家! 一个最基本的I/O问题 这个快闪屏窗口为什么无法显示 焦急!StringBuffer问题 ●●.ser 文件是如何生成的????? 鼠标移动事件,eclipse无报错,可是控制台终止程序,没有结果。为什么运行不了的呢?请大神告知!! 疑问,关于二进制流 为什么在程序中用import MyClass;导入自己写的类时提示要加.?
char c = s.charAt(s.length() - 1);
String s = "ABCDEFG" last = s.charAt(s.length() - 1);
temp=temp.substring(temp.length()-1,temp.length());
so that temp is "G"
char last;
if (s != null){
last = s.charAt(s.length() -1);
}
自己用substring试一试不就知道了么?动动手吧
chatAt才是正解,返回的是char
subString返回的是String
char last;
if (s != null){
last = s.charAt(s.length() -1);
}