標題:
TQC210
[打印本頁]
作者:
b790113g
時間:
2012-3-10 20:08
標題:
TQC210
import java.util.* ;
public class jva210{
public static void main(String args[]){
System.out.println("請輸入字串");
Scanner s = new Scanner(System.in);
String str = s.next();
System.out.println("請輸入要搜尋的字元或字串");
String str2 = s.next();
int loc = -1;
boolean find = false;
boolean afind = false ;
do{
if( (loc = str.indexOf(str2,loc+1)) > -1 ){
if(!find){
System.out.println("第幾個位置找到了");
find = true;
}
afind = true ;
System.out.println(loc+1);
}
}while(loc != -1);
if(!afind) System.out.println("字元不在字串中");
}
}
複製代碼
作者:
p17johnny
時間:
2012-6-7 20:29
import java.io.*;
public class JVA210{
public static void main(String args[]){
int site;
boolean find,find1;
try{
System.out.println("請輸入字串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
System.out.println("請輸入要搜尋的字元或字串");
String str2 = br.readLine();
site = -1;
find = false;
find1 = false;
do{
if( (site = str.indexOf(str2,site+1)) > -1 ){
find = true;
if(!find1) System.out.println("第幾個位置找到了");
find1 = true;
System.out.println(site+1);
}
}while(site != -1);
if(!find)
System.out.println("您要搜尋的的字不在字串中");
}catch(Exception e){
}
}
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2