In: Computer Science
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA
zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75);
^ symbol: method difference(int,int) location: class MidtermProblems 1 error
import java.lang.Math;
public class MidtermProblems {
public static String difference(int a, int b) {
int diff = Math.abs(a - b);
String ans = "";
if (diff == 0) {
ans = "EQUAL";
} else if (diff > 10) {
ans = "Big Difference " + diff;
} else if (diff <= 10) {
ans = "Small Difference " + diff;
}
return ans;
}
}
Before using s we have to declare its data type . so, we have to declare 's' as String datatype
Note: in my answer screen shot , in the 19th line I added the datatype to 's' as String
Note: if you need use public before class name
Source Code:
import java.lang.Math;
class MidtermProblems {
public static String difference(int a, int b) {
int diff = Math.abs(a - b);
String ans = "";
if (diff == 0) {
ans = "EQUAL";
}
else if (diff > 10) {
ans = "Big Difference " + diff;
}
else if (diff <= 10) {
ans = "Small Difference " + diff;
}
return ans;
}
public static void main(String[] args) {
String s = MidtermProblems.difference(75,
75);
System.out.println(s);
}
}
Sample output: