javajava json字符串串问题

如何在java中从键盘输入两个字符串,并判断一个在另一个中出现的次数?
能不能给我看一下完整的代码,我刚开始学java还不是很清楚。谢谢了!
import 相关信息.io.*;
import java.lang.S
public class Ct {
*计算strsi在strdi中出现的次数
public static int count(String strsi, String strdi) {
if((strsi == null) ||(strdi == null)) {
System.out.println("传入字符串为空!");
return -1;
int iLength_Si = strsi.length();
int iLength_Di = strdi.length();
int index = 0;
int iNum = 0;
if(iLength_Si > iLength_Di)
while(index < iLength_Di) {
index = strdi.indexOf(strsi, index);
if(index < 0) {
//index += iLength_Si;
public static void main(String[] argv) {
String str1 =
String str2 =
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("输入字符串1:");
str1 = in.readLine();
System.out.print("输入字符串2:");
str2 = in.readLine();
System.out.println("字符串1在字符串2中出现的次数为: " + Ct.count(str1, str2));
*System.out.println("字符串2在字符串1中出现的次数为: " + Ct.count(str2, str1));
}catch(IOException e) {
System.out.println("输入出错;");
e.printStackTrace();
import 相关信息.io.*;
import java.lang.S
public class Ct {
*计算strsi在strdi中出现的次数
public static int count(String strsi, String strdi) {
if((strsi == null) ||(strdi == null)) {
System.out.println("传入字符串为空!");
return -1;
int iLength_Si = strsi.length();
int iLength_Di = strdi.length();
int index = 0;
int iNum = 0;
if(iLength_Si > iLength_Di)
while(index < iLength_Di) {
index = strdi.indexOf(strsi, index);
if(index < 0) {
//index += iLength_Si;
public static void main(String[] argv) {
String str1 =
String str2 =
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("输入字符串1:");
str1 = in.readLine();
System.out.print("输入字符串2:");
str2 = in.readLine();
System.out.println("字符串1在字符串2中出现的次数为: " + Ct.count(str1, str2));
*System.out.println("字符串2在字符串1中出现的次数为: " + Ct.count(str2, str1));
}catch(IOException e) {
System.out.println("输入出错;");
e.printStackTrace();
其他答案(共2个回答)
给你代码片段:BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));...
判断一个用一个数记录就行了
java.util.Scanner 如下public static void main(String[] args) {while(true){Scann...
double[] d=new double[10]; int[] f=new int[d.length]; for(int i=0
答: 急 急 急 有啊,怎么不把问题写的祥细一点!
答: 这个要设计到JNI的开发,就是用Java来调用C语言的函数库,还要编写缓冲器来解决传输问题,还有就是网络协议一定要了解,做的时候要用多线程来控制你所有的缓冲器,...
答: 所谓的网络编程,不论c还是java,本质上都是通过socket进行数据传输;一般情况下可以使用的传输协议有tcp、udp、ftp等等,这些协议为网络变成提供基本...
大家还关注
确定举报此问题
举报原因(必选):
广告或垃圾信息
激进时政或意识形态话题
不雅词句或人身攻击
侵犯他人隐私
其它违法和不良信息
报告,这不是个问题
报告原因(必选):
这不是个问题
这个问题分类似乎错了
这个不是我熟悉的地区
相关问答:123456789101112131415鍗氬?鍒嗙被锛}

我要回帖

更多关于 java截取字符串 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信