出于某种原因,我将布尔值和字符串突出显示为错误,我直接从教科书中复制了这段代码--为什么它不能工作?套餐实践;
public class practice{
public boolean isUniqueChars(string str){
if (str.length() > 256)
return false;
boolean[] char_set = new boolean[256];
for (int i = 0; i< str.length(); i++){
int val = str.charAt(i);
if (char_set[val]) {
return false;
char_set[val] = true;
}
return true;
}
}
Errors: Multiple markers at this line
- string cannot be resolved to a type
- Syntax error on token "boolean", @
expected
- Syntax error on token ")", -> expected
- Syntax error on token(s), misplaced
construct(s)发布于 2014-12-20 05:50:48
试试看:
package practice;
/**
*
* @author manoj.sharma
*/
public class Test{
public static void main(String [] a){
System.out.println(new Test().isUniqueChars("Hello world"));
}
public boolean isUniqueChars(String str){
if (str.length() > 256)
return false;
boolean[] char_set = new boolean[256];
for (int i = 0; i< str.length(); i++){
int val = str.charAt(i);
if (char_set[val]) {
return false;
}
char_set[val] = true;
}
return true;
}
}发布于 2014-12-20 05:48:32
public boolean isUniqueChars(string str){似乎是一个错误,字符串应该是String
发布于 2014-12-20 06:47:20
在Java中,字符串声明使用"S“。
isUniqueChars(String str)https://stackoverflow.com/questions/27577349
复制相似问题