Java Can';我想不出这个密码。请给出一些见解
我不断收到错误Java Can';我想不出这个密码。请给出一些见解,java,methods,Java,Methods,我不断收到错误方法外接程序类DebugThree2无法应用于给定类型,二进制运算符“-”的操作数类型错误 // This application displays some math facts public class DebugThree2 { public static void main(String args[]) { add(); subtract(); System.out.println("Java"); int a =
方法外接程序类DebugThree2无法应用于给定类型
,二进制运算符“-”的操作数类型错误
// This application displays some math facts
public class DebugThree2 {
public static void main(String args[]) {
add();
subtract();
System.out.println("Java");
int a = 2, b = 5, c = 10;
add("a" + "b");
add("b" + "c");
subtract("c" - "a");
}
public static void add() {
System.out.println("The sum of " + "a" + "and" + "b" + "is" + "a" + "b");
}
public static void subtract() {
System.out.println("The difference between " + "a" + "and" + "b" + "is" + "a" - "b");
}
}
我想这样的东西可能更适合你。您正试图从(字符串)a中减去(字符串)b
您必须使用它们的实际值,不包括引号 为什么将变量放在
“
”之间?为什么方法不接收任何参数?
public static void main(String args[])
{
add();
subtract();
System.out.println("Java");
int a = 2, b = 5, c = 10;
add(a,b);
add(b,c);
subtract(c,a);
}
public static void add(int a, int b)
{
System.out.println("The sum of " + a +
" and " + b + " is " + (a+b));
}
public static void subtract(int a, int b)
{
System.out.println("The difference between " +
a + " and " + b + " is " + (a-b));
}
"a" - "b"