【发布时间】:2018-04-30 15:24:28
【问题描述】:
我必须编写一个程序来打印用户输入的字符串,并且像第一个一样的每个字母都替换为“#”:
mum -> #u#
dad -> #a#
Swiss -> #wi## //also if it is UpperCase
Albert -> Albert //no letter is like the first
用户可以输入他想要多少个字符串。我想用 Split 方法拆分字符串,但它不适用于 ArrayList。
import java.util.*;
public class CensuraLaPrima {
public static void main(String[] args) {
Scanner s= new Scanner (System.in);
String tdc;
ArrayList <String> Parolecens= new ArrayList <String>();
while (s.hasNextLine()) {
tdc=s.nextLine();
Parolecens.add(tdc);
}
System.out.println(Parolecens);
}
}
【问题讨论】:
-
我已经标记了 Java...
-
您的代码没有显示任何尝试...我不明白您在哪里尝试拆分以及为什么?你的问题是什么 ?如何寻找像第一个字母?怎么把这封信改成#?或者如何捕捉用户输入的单词?
-
它不起作用没有错误描述。添加错误消息或预期数据以及您得到的结果。
-
首先,欢迎。其次,
Parolecens不应以大写字母开头。它太混乱了,不推荐。第三,请进行更多研究并阅读我将在下一条评论中提供的链接。此外,这将对您有很大帮助 - Efficient way to replace chars in a string (java)? -
Please, do more research 然后发布您尝试过的内容,并清楚地解释什么无效并提供Minimal, Complete, and Verifiable example。阅读How to Ask a good question。请务必take the tour 并阅读this。
标签: java arrays string arraylist