Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 查找字符串的位置
sunandjava





发贴: 1
积分: 0
于 2006-09-23 09:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

import java.io.*;
public class Search1
{
public static void main(String args[])
{
int count=0,first=0,second=0;
String text="ab cd ef g";
String s="";
String subtext=text;
System.out.println(text);
System.out.println("请输入你要查找的字符串:");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader (System.in));
s=in.readLine();
}
catch(IOException e){}
for(int i=1;i<=text.length();i+=second+1)
{
second=subtext.indexOf("");
String temp=subtext.substring(first,second);
if(s.equalsIgnoreCase(temp)) count++;
subtext=subtext.substring(second+1);
}


if(count==0)
System.out.print("it not exists");
else
System.out.print("it exists");
}
}

请大伙帮我看看这个程序啊,我搞了好久 了都没有结果,现在只有寄希望于各位大虾了(要求:输入任意的字符串,能够查找到它是否存在,最好还能统计一下这个字符串总共出现了几次,以及它出现的位置.)


why edited on 2006-09-23 16:57



话题树型展开
人气 标题 作者 字数 发贴时间
8786 查找字符串的位置 sunandjava 856 2006-09-23 09:06
7107 Re:查找字符串的位置 wwhui 38 2006-09-24 12:46
7295 Re:查找字符串的位置 why 702 2006-09-24 18:53

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923