返回列表 發帖

Java 105 字串索引

本帖最後由 鄭繼威 於 2023-5-13 10:56 編輯

1. 題目說明:
請開啟C:\ANS.CSF\JP01資料夾中的JPD01.java進行編寫。依下列題意進行作答:輸入一個字串,再於題目提供的英文短文中尋找及輸出所在位置,使輸出值符合題意要求。檔案名稱請另存新檔為JPA01.java,儲存於C:\ANS.CSF\JP01資料夾,再進行評分。

2. 設計說明:
(1) 專案中已提供一段英文短文於常數dreams中。
(2) 請在main主程式中,讓使用者輸入單字,以輸入的單字在常數dreams英文短文中,尋找第一個位置及最後一個位置再取出這兩個位置間的字串,將此三個值傳至print程式進行輸出
* 提示:字串索引由0開始,輸出值必須加1。
(3) 若輸入不存在的單字,位置必須顯示為0,擷取字串為空值(無空格);若單字只出現一次,則擷取單字之後的所有文字

3. 輸入輸出:
輸入說明
一個字串

輸出說明
第一個位置first
最後一個位置last
擷取兩個位置之間的字串capture(輸出最後一行後不自動換行)

String dreams = "There are moments in life when you miss someone so much that "
                                + "you just want to pick them from your dreams and hug them for real! Dream what "
                                + "you want to dream;go where you want to go;be what you want to be,because you have "
                                + "only one life and one chance to do all the things you want to do";

範例輸入1
want
範例輸出1
first:71
last:276
capture:want to pick them from your dreams and hug them for real! Dream what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the things you want


範例輸入2
things
範例輸出2
first:265
last:0
capture:things you want to do


範例輸入3
substring
範例輸出3
first:0
last:0
capture:


本帖隱藏的內容需要回復才可以瀏覽

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表