当前位置:网站首页>错误: 找不到符号
错误: 找不到符号
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)
边栏推荐
猜你喜欢
[算法] 剑指offer2 golang 面试题10:和为k的子数组
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
Office prompts that your license is not genuine pop-up box solution
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
Fabrication d'un sac à dos simple fairygui
RTKLIB: demo5 b34f.1 vs b33
基本Dos命令
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
随机推荐
FairyGUI簡單背包的制作
341. Flatten nested list iterator
There is no red exclamation mark after SVN update
What are the advantages of using SQL in Excel VBA
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
In 2020, the average salary of IT industry exceeded 170000, ranking first
雇佣收银员【差分约束】
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
Introduction to the daily practice column of the Blue Bridge Cup
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
Detailed explanation of balanced binary tree is easy to understand
FairyGUI增益BUFF數值改變的顯示
Solution to the problem of automatic login in Yanshan University Campus Network
Wechat applet development experience
[algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
Force buckle 1189 Maximum number of "balloons"
Liste des boucles de l'interface graphique de défaillance
rtklib单点定位spp使用抗差估计遇到的问题及解决