当前位置:网站首页>错误: 找不到符号
错误: 找不到符号
2022-07-06 09:18:00 【非风之想】
错误提示
StringTest_2.java:25: 错误: 找不到符号
while((index=indexOf(key))!=-1)
^
符号: 方法 indexof(String)
位置: 类 StringTest_2
1 个错误
代码如下
public class StringTest_2
{
public static void main(String[] args)
{
String str="abcbjfbeabcjefjabcjepofkjabcniabc";
String key="abc";
int count=getKeyStringCount(str,key);
System.out.println("count="+count);
}
public static int getKeyStringCount(String str,String key)
{
//定义计数器
int count=0;
//定义变量记录key出现的位置
int index=0;
while((index=indexOf(key))!=-1)
{
str=str.substring(index+key.length());
count++;
}
return count;
}
}
常见的找不到符号就是符合错误或没有定义符号,我检查了符号没有错误,又试了导包,都没用。
后面发现while((index=indexOf(key))!=-1)一句中indexOf(key)没有用str对象调用,int indexOf(String str)的作用是返回指定字符串第一次出现在字符串的索引,没有调用字符串对象就不能就不能实现其功能!
解决方法
所以就是将while((index=indexOf(key))!=-1)
改成while((index=str.indexOf(key))!=-1)
边栏推荐
- There is no red exclamation mark after SVN update
- GNSS定位精度指标计算
- FairyGUI人物状态弹窗
- FairyGUI循环列表
- (the first set of course design) 1-4 message passing interface (100 points) (simulation: thread)
- Fairygui character status Popup
- Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
- Unity3D制作注册登录界面,并实现场景跳转
- RTKLIB: demo5 b34f.1 vs b33
- FairyGUI循環列錶
猜你喜欢

FairyGUI复选框与进度条的组合使用

Naive Bayesian theory derivation

FairyGUI循环列表

平衡二叉树详解 通俗易懂

Fabrication d'un sac à dos simple fairygui

Detailed explanation of balanced binary tree is easy to understand

Problems and solutions of robust estimation in rtklib single point location spp
![[algorithm] sword finger offer2 golang interview question 2: binary addition](/img/c2/6f6c3bd4d70252ba73addad6a3a9c1.png)
[algorithm] sword finger offer2 golang interview question 2: binary addition

RTKLIB: demo5 b34f.1 vs b33

Teach you to release a DeNO module hand in hand
随机推荐
【无标题】
The port is occupied because the service is not shut down normally
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
Itext 7 生成PDF总结
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
[算法] 劍指offer2 golang 面試題2:二進制加法
基于rtklib源码进行片上移植的思路分享
Unity3D制作注册登录界面,并实现场景跳转
Unity3D,阿里云服务器,平台配置
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
[leetcode19] delete the penultimate node in the linked list
IText 7 generate PDF summary
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K
雇佣收银员【差分约束】
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
Fairygui joystick