我的任务是创建一个方法,该方法将接受用户的3位数字输入并颠倒其顺序,然后以该新顺序将其返回,而无需将任何内容转换为字符串,所有这些均保持为int形式。我无法弄清楚如何在不将值加在一起的情况下返回新数字(第一,第二,三);
public class Lab01
{
public int sumTheDigits(int num)
{
int one;
int two;
int three;
one = num % 10;
two = (num/10) % 10;
three = num / 100;
return one + two + three;
}
public int reverseTheOrder(int num)
{
int first;
int second;
int third;
third = num / 100;
second = (num/10) % 10;
first = num % 10;
return ?;
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Lab01 lab = new Lab01();
System.out.println("Enter a three digit number: ");
int theNum = input.nextInt();
int theSum = lab.sumTheDigits(theNum);
int theReverse = lab.reverseTheOrder(theSum);
System.out.println("The sum of the digits of " + theNum + " is " + theSum);
System.,out.println(theNum + " reversed is " + theReverse);
}
}
您可以尝试以下任意长度的数字