我正在尝试解决codingbat的问题。我必须编写一个给定两个非负 int 值的方法,如果它们的最后一位数字相同,则返回 true。我正在尝试快速测试我的解决方案是否正确,因此我创建了一个 LastDigit 类并写道:
public class LastDigit{
public static void main(String[] args){
System.out.println(lastDigit(7,17));
System.out.println(lastDigit(6,17));
System.out.println(lastDigit(3,113));
}
public boolean lastDigit(int a, int b){
return (a%10==b%10);
}
}
我得到了问题
non-static method lastDigit(int,int) cannot be referenced from a static context
但问题不在于消息(我正在想象我必须以某种方式创建一个对象或类似的东西),而是如何快速测试一个方法?
谢谢 :)