JAVA程序改错改错public class Modify5t { public static void pain(String [] args) {int a = 20;int b = 50;int c = sum(a, b);System.out.println("The sum is: " + c); } public int sum(int a, int b) {return a + b; }}急求!

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/13 02:10:23
JAVA程序改错改错public class Modify5t {    public static void pain(String [] args) {int a = 20;int b = 50;int c = sum(a, b);System.out.println(
xSMO@=?N& qĉ;RXB%)ĂJ)MHsIBK~LkԿc5U9pegfͼ}IhK.;4ՁW=䫖J$ӒabcM@ˀ$WYe hFVs Fl(*Xę-{6r$9Y0`*#fsPHV#sO^h PG`̃d4N$h%Zu+z t42yofrf5lNg〯80)"aS' kPDL[JWnٙM+YYa[;oMm~2n}Jvt-}d1w{k#ͩw=F_C۬8"DR1u8kbm! ý*:Ֆ/5а2I(fC U}n1BBDT'ӽFm Y'qY,9<0`\j8G2

JAVA程序改错改错public class Modify5t { public static void pain(String [] args) {int a = 20;int b = 50;int c = sum(a, b);System.out.println("The sum is: " + c); } public int sum(int a, int b) {return a + b; }}急求!
JAVA程序改错改错
public class Modify5t {
public static void pain(String [] args) {
int a = 20;
int b = 50;
int c = sum(a, b);
System.out.println("The sum is: " + c);
}
public int sum(int a, int b) {
return a + b;
}
}
急求!

JAVA程序改错改错public class Modify5t { public static void pain(String [] args) {int a = 20;int b = 50;int c = sum(a, b);System.out.println("The sum is: " + c); } public int sum(int a, int b) {return a + b; }}急求!
public static void pain(String [] args) {
public static void main(String [] args) {
细心很重要!不过问题还没解决、、、
解决方案:
第一种方法
sum 方法前面加上static关键字,一定行的.因为main是方法静态方法,静态方法只能调用静态成员.
第二种方法
静态方法想调用实例成员的话,就在main方法里面实例化一个类对象,通过对象名调用sum方法.
public class Modify5t {
public static void pain(String [] args) {
Modify5t M=new Modify5t();
int a = 20;
int b = 50;
int c =M. sum(a, b);
System.out.println("The sum is: " + c);
}
public int sum(int a, int b) {
return a + b;
}
}