// 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");
}
}
我不断收到错误method add in class DebugThree2 cannot be applied to given types
,bad operand types for binary operator '-'
答案 0 :(得分:0)
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。
"a" - "b"
您必须使用其实际值,不包括引号。