有关字符串返回索引值的问题 本帖最后由 java2000_net 于 2008-08-05 09:13:59 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package test;public class Main { public static void main(String[] args) { String s1 = "12300000000"; String s2 = "12301000000"; String s3 = "12301500000"; System.out.println(getIndex(s1)); System.out.println(getIndex(s2)); System.out.println(getIndex(s3)); } public static int getIndex(String str) { if (str == null) { return -1; } for (int i = str.length() - 1; i >= 0; i--) { char ch = str.charAt(i); if (ch != '0') { return i; } } return -1; }} 有没有可能运行gui 然后还能生成txt文本保存数据呢 请教Java写文件的问题 字符串和字节数组之间的转换 ---在线等候中---急!! applet IE6.0显示不了 求助java关于日历的代码 如何实现Swing Jtable某列 单元格中的数据为“禁用”字眼时设置该行颜色。 在线等候!急 关于创建对象的问题求问 好久没有来了,以前的小游戏改了一下,大家帮忙看看,提提好的意见,来者给分 有没有大佬帮助我这个初学者 关于一段代码如何去分析的问题,不难~~~~ java读取文件变成字符串的问题
package test;public class Main { public static void main(String[] args) {
String s1 = "12300000000";
String s2 = "12301000000";
String s3 = "12301500000";
System.out.println(getIndex(s1));
System.out.println(getIndex(s2));
System.out.println(getIndex(s3));
} public static int getIndex(String str) {
if (str == null) {
return -1;
}
for (int i = str.length() - 1; i >= 0; i--) {
char ch = str.charAt(i);
if (ch != '0') {
return i;
}
}
return -1;
}
}