由于某种原因,它突出显示布尔值和字符串为错误,我直接从教科书中复制了此代码,为什么它不起作用?包装实践;
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)
好吧,试试这个:
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;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句