当前位置:网站首页>错误: 找不到符号
错误: 找不到符号
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)
边栏推荐
- Fairygui loop list
- Guided package method in idea
- KF UD分解之UD分解基础篇【1】
- Unity场景跳转及退出
- FairyGUI增益BUFF數值改變的顯示
- [dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
- [untitled]
- SVN更新后不出现红色感叹号
- It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
- Prove the time complexity of heap sorting
猜你喜欢

idea中导包方法

FGUI工程打包发布&导入Unity&将UI显示出来的方式

NovAtel 板卡OEM617D配置步骤记录

Office提示您的许可证不是正版弹框解决

地球围绕太阳转

Theoretical derivation of support vector machine
![[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K](/img/8c/1b6ba3b1830ad28176190170c98628.png)
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K

3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
![[algorithm] sword finger offer2 golang interview question 5: maximum product of word length](/img/e0/cea31070d6365eb57013cdead4a175.png)
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length

idea问题记录
随机推荐
雇佣收银员【差分约束】
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
音乐播放(Toggle && PlayerPrefs)
[algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
Database table splitting strategy
Containers and Devops: container based Devops delivery pipeline
Unity场景跳转及退出
Easy to use shortcut keys in idea
MySQL shutdown is slow
(the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
Basic DOS commands
[offer9] implement queues with two stacks
SVN更新后不出现红色感叹号
FairyGUI循環列錶
How to improve the deletion speed of sequential class containers?
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
GNSS定位精度指标计算