2023-11-11
54. 替换数字(第八期模拟笔试)
思路:c++可以用双指针,Java字符串是不能改变的,直接用替换
import java.util.Scanner; class Main{ public static void main(String[] args) { // String s="a1b2c3"; Scanner sc=new Scanner(System.in); String s=sc.next(); // String s="a1b2c3d4f5g6"; s=xxx(s); System.out.println(s); } public static String xxx(String s){ int n=s.length(); for(int i=0;i<n;i++){ char c=s.charAt(i); if(c>='0' && c<='9'){ String s1=s.substring(0,i); String s2=s.substring(i+1,s.length());//a number b2c3 s=s1+"number"+s2; i+=5; n+=5; } } return s; } }
标签:String,54,笔试,第八期,替换,Scanner From: https://www.cnblogs.com/youye9527/p/17826031.html