怎么可能用one
替换每个1
,用two
替换每个2
,用three
替换每个3
……从输入?
我的代码:
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String Input = JOptionPane.showInputDialog("Text:");
String Output;
//replace
Output = Input.replaceAll("1", "one");
Output = Input.replaceAll("2", "two");
//Output
System.out.println(Output);
}
}
它只与一个替换项一起工作。
发布于 2018-07-01 23:16:20
您需要在OutPut
上第二次调用replaceAll
:
Output = Input.replaceAll("1", "one");
Output = Output.replaceAll("2", "two");
或者只是流利地调用replaceAll
:
Output = Input.replaceAll("1", "one").replaceAll("2", "two");
https://stackoverflow.com/questions/51124460
复制相似问题