我正在努力理解声明和调用类的概念以及它们之间的变量流量。在我现在拥有的代码中,我相信有几个问题,但现在的主要问题是主方法无法使用另一种方法的返回值,我相信我做对了。编码:
import java.util.*;
import java.io.*;
class Uke63{
public static void main(String[]args){
char c='t';
String tekst="Jabba the Hutt var en stygg fyr";
forekommer(c, tekst);
System.out.println(retval.forekommer);
}
static boolean forekommer(char c, String tekst){
boolean retval=tekst.contains(c);
return retval;
}
}
以及我在尝试编译时遇到的错误:(我确实看到它没有找到该值,但我需要一些帮助以使其找到该特定值。)
makri@Marius-samlap:~/Programmering/Ukeoppgaver$ javac Uke63.java
Uke63.java:12: error: cannot find symbol
System.out.println(retval.forekommer);
^
symbol: variable retval
location: class Uke63
Uke63.java:18: error: method contains in class String cannot be applied to given types;
boolean retval=tekst.contains(c);
^
required: CharSequence
found: char
reason: actual argument char cannot be converted to CharSequence by method invocation conversion
2 errors