当前位置:网站首页>错误: 找不到符号
错误: 找不到符号
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)
边栏推荐
- Meanings and differences of PV, UV, IP, VV, CV
- What are the advantages of using SQL in Excel VBA
- Itext 7 生成PDF总结
- Idea problem record
- How to improve the deletion speed of sequential class containers?
- 地球围绕太阳转
- Solution to the problem of automatic login in Yanshan University Campus Network
- Mixed use of fairygui button dynamics
- 【RTKLIB 2.4.3 b34 】版本更新简介一
- [算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
猜你喜欢
NovAtel 板卡OEM617D配置步骤记录
C programming exercise
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
FairyGUI条子家族(滚动条,滑动条,进度条)
FairyGUI复选框与进度条的组合使用
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
平衡二叉树详解 通俗易懂
Mysql database index
FairyGUI人物状态弹窗
Problems and solutions of robust estimation in rtklib single point location spp
随机推荐
Special palindromes of daily practice of Blue Bridge Cup
Usage differences between isempty and isblank
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
Wechat applet development experience
GPS高程拟合抗差中误差的求取代码实现
(the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
燕山大学校园网自动登录问题解决方案
使用rtknavi进行RT-PPP测试
染色法判定二分图
FairyGUI复选框与进度条的组合使用
rtklib单点定位spp使用抗差估计遇到的问题及解决
Fabrication of fairygui simple Backpack
[offer29] sorted circular linked list
Problems and solutions of robust estimation in rtklib single point location spp
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
Database course design: college educational administration management system (including code)
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
Derivation of logistic regression theory
Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
[leetcode15] sum of three numbers