模板网站制作公司,教育信息化建设网站,wordpress购物网站,seo服务公司深圳题目 思路
创建两个字符串 temp 和 ret 创建指针i用来遍历字符串通过i遍历字符串,如果遇到数字则将这个数组加到字符串temp中 i,如果遇到字母,则判断temp字符串的长度和ret字符串的长度,如果tempret则说明这个字符串不是要的字符串,如果tempret则说明此时temp字符串是…题目 思路
创建两个字符串 temp 和 ret 创建指针i用来遍历字符串通过i遍历字符串,如果遇到数字则将这个数组加到字符串temp中 i,如果遇到字母,则判断temp字符串的长度和ret字符串的长度,如果tempret则说明这个字符串不是要的字符串,如果tempret则说明此时temp字符串是暂时的最大值,就将temp 的值赋给ret遍历字符串结束,ret中存在的字符串就是我们想要的结果
代码
import java.util.Scanner;// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {public static void main(String[] args) {Scanner in new Scanner(System.in);String ret ;String temp ;String str in.nextLine();int i 0;while(i str.length()){if(Character.isDigit(str.charAt(i))){temp str.charAt(i);}else{if(temp.length()ret.length()){ret temp;}temp ;}i;}if(temp.length()ret.length()){ret temp;}System.out.print(ret);}
}