【发布时间】:2014-05-24 12:55:49
【问题描述】:
我已经编写了这段代码,但我遇到了问题。当我写“替换别的东西”时,我想打印“嗨别的东西”。我该怎么做?
import java.util.Scanner;
public class replace something
{
public static void main(String[] args)
{
Scanner cumle = new Scanner(System.in);
System.out.println("Enter the sentence u want to replace :");
String str1 = cumle.next();
if (str1.contains("replace"))
{
str1 = str1.replace("replace", "Hi");
System.out.println("Replaced Sentence: " + str1);
}
else
{
System.out.println("Sentence doesn't contains that...");
}
}
}
【问题讨论】:
-
检查您正在打印的字符串...
-
详细说明,修复错字:
System.out.println("Replaced Sentence: " + str);
标签: java string replace contains