indexOf的問題
我的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海
討論串 (同標題文章)
java 近期熱門文章
PTT數位生活區 即時熱門文章