看板java
标 题indexOf的问题
发信站无名小站 (Sat Mar 11 10:37:36 2006)
转信站ptt!ctu-reader!Spring!news.nctu!news.ntu!news.ee.ttu!netnews.csie.nctu
我的Input:
MoNeY IS iN frOnT oF mANy tHIngS bUT nEXt tO sOmEtHiNg.
(注:Phrase 1 是 money)
我的Output是要像这样:
MONEY IS IN FRONT OF MANY THINGS BUT NEXT TO SOMETHING.
The first occurrence of Phrase 1 in this string was: 0
The total number of strings which contain key phrase 1 is 1
但是我失败了,有没有哪位大大愿意帮我看看哪里出错了呢?
My Code:
------
import java.util.*;
public class test
{
public static void main(String[ ] args)
{
final String PHRASE1 = "MONEY";
String strLine = "", strLineUpper;
int
wherekey1, wherekey2, wherekey3,
numKey1 = 0, numKey2 = 0, numKey3 = 0;
Scanner scan = new Scanner(System.in);
scan.nextLine();
strLine = scan.nextLine().trim();
strLineUpper = strLine.toUpperCase();
wherekey1 = strLineUpper.indexOf("PHRASE1");
if(wherekey1 > -1)
numKey1++;
System.out.println(strLine.toUpperCase());
if(wherekey1 > -1)
{
System.out.println("The first occurrence " +
"of Phrase 1 in this string was: "
+ wherekey1);
}
System.out.println("The total number of strings "
+ "which contain key phrase 1 is "
+ numKey1);
} // End public static void main
} // End public class StrProc
--
夫兵者不祥之器物或恶之故有道者不处君子居则贵左用兵则贵右兵者不祥之器非君子
之器不得已而用之恬淡为上胜而不美而美之者是乐杀人夫乐杀人者则不可得志於天下
矣吉事尚左凶事尚右偏将军居左上将军居右言以丧礼处之杀人之众以哀悲泣之战胜以
丧礼处之道常无名朴虽小天下莫能臣侯王若能守之万物将自宾天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦将知止知止可以不殆iba-dip0.nat.okstate.edu海