这是一个我难以理解的作业问题。我的教授建议查找Math.abs()方法。在一个名为Digit的类中,编写一个名为lastDigit的方法,返回一个整数的最后一位数字
我需要利用主方法中的扫描仪对象来查询用户的输入,然后使用扫描仪输入作为参数指定方法。在名为Digit的类中,编写一个名为lastDigit的方法,该方法返回整数的最后一位数字。例如,lastDigit(3572)应返回2
这是我目前有:处理模时
import java.util.Scanner;
public class Digit {
public static void main(String[] args) {
Scanner scanIn = new Scanner(System.in);
System.out.print("Please enter a number: ");
int = scanIn.nextInt();
}
public int lastDigit(int number){
int last =number%10;
return last;
}
}
SO有助于解决编程问题,*不管他们是否有家庭作业。虽然这不是一个[好问题](http://stackoverflow.com/help/how-to-ask),因为它不清楚你的问题是什么。 – usr2564301 2014-09-27 20:07:07
我无法通过扫描仪调用我的lastDigit方法 – 2014-09-27 20:08:33
啊等待。 Java在负输入上返回一个负数的模数?这可能会澄清你的教授给你的提示。 – usr2564301 2014-09-27 20:08:44