题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3323
Somali Pirates

中文大意
给定一些候选密码行,要求删除密码中的所有数字, 并按原始顺序打印其他字符。此外, 密码仅由数字和英文字母组成。
核心思路
字符串转为char类型的数组,遍历数组,去除数字即可
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int t=sc.nextInt();
sc.nextLine();
for(int i=0;i<t;i++)
{
String str=sc.nextLine();
String s="";
char[] c=str.toCharArray();
for(int j=0;j<c.length;j++)
{
if(!Character.isDigit(c[j]))
{
s+=c[j];
}
}
System.out.println(s);
}
}
}
}
本文介绍了一种从密码字符串中移除所有数字的方法,并保留其余字符。通过将字符串转换为字符数组,遍历该数组并检查每个字符是否为数字,从而实现目标。此过程使用了Java语言。
960

被折叠的 条评论
为什么被折叠?



