String d1="I like to watch the sun set with my friend.";
String d2="The Best Places To Watch The Sunset.";
String d3="My friend watch the sun come up.";
句子是d1 d2 d3,输入句子中的单词,返回单词所在句子编号
String d2="The Best Places To Watch The Sunset.";
String d3="My friend watch the sun come up.";
句子是d1 d2 d3,输入句子中的单词,返回单词所在句子编号
解决方案 »
- Word文件流的读取和写入
- struts2 ActionSupport 及 项目起名问题,高手请进!
- 谁有支持火狐 的xml无限级树
- jsf上传文件中文问题
- Spring mvc 跳转后路径问题,求解,
- 大家讨论一下在java窗体里如何把数据库里的数据生成报表并打印出来,就像VB里的报表一样.
- 初次使用java native函数最常见的问题
- HELP!!! stand alone java swing application + xml file?
- how to do ?
- 学习J2EE怎么上手呀,总是没什么心得。
- tomcat集群 session复制的问题
- java里的readLine找不到下一行是什么情况?
public static void main(String[] args) {
String d1="I like to watch the sun set with my friend.";
String d2="The Best Places To Watch The Sunset.";
String d3="My friend watch the sun come up.";
String word = "My";
String resultString = "单词在";
if(d1.contains(word)){
resultString += "d1、";
}
if(d2.contains(word)){
resultString += "d2、";
}
if(d3.contains(word)){
resultString += "d3、";
}
resultString = resultString.substring(0,resultString.length()-1);
resultString += "中";
System.out.println(resultString);
}
String d2="The Best Places To Watch The Sunset.";
String d3="My friend watch the sun come up.";
String demo = "like";
if (d1.contains(demo)) {
System.out.println("搜索结果在的d1中");
}else if(d2.contains(demo)){
System.out.println("搜索结果在的d2中");
}else if(d3.contains(demo)){
System.out.println("搜索结果在的d3中");
}else{
System.out.println("您的搜索不在范围内!");
}
public static final String SPACE = " "; public static void main(String[] args) {
String d1="I like to watch the sun set with my friend.";
String d2="The Best Places To Watch The Sunset.";
String d3="My friend watch the sun come up.";
String[] array = {d1,d2,d3};
System.out.println(confirm(array, "come"));
}
public static String confirm(String[] array,String word){
for (String s : array) {
String[] arr = s.split(SPACE);
for (String string : arr) {
if (string.equals(word)) {
return s;
}
}
}
return "No Such Word!";
}}