Java 如何获取步骤1中最右边的数字?那么如何获取非';第2步是否包括?

Java 如何获取步骤1中最右边的数字?那么如何获取非';第2步是否包括?,java,java.util.scanner,Java,Java.util.scanner,我看到了一些其他问题,并看到位置值(如%10)应该给出数字,但我不知道如何根据问题进行更改?以下是一些建议 要获取最低有效位,请使用带10的余数运算符(%) 要获得下一个数字,将原始数字除以10,然后对商应用余数运算符 对于每一个其他数字,需要在数字乘以2后应用余数运算符和除法运算符。所以14等于1+4,你们应该可以像上面一样计算出来 您可以继续此操作,直到起始编号为0。或者在循环中重复4次,每个循环获得两位数,并执行适当的求和操作 完成后,您只需测试所需值的结果 在这里询问之前,至少尝试这样做

我看到了一些其他问题,并看到位置值(如%10)应该给出数字,但我不知道如何根据问题进行更改?

以下是一些建议

  • 要获取最低有效位,请使用带10的余数运算符(%)
  • 要获得下一个数字,将原始数字除以10,然后对商应用余数运算符
  • 对于每一个其他数字,需要在数字乘以2后应用余数运算符和除法运算符。所以14等于1+4,你们应该可以像上面一样计算出来
  • 您可以继续此操作,直到起始编号为0。或者在循环中重复4次,每个循环获得两位数,并执行适当的求和操作
  • 完成后,您只需测试所需值的结果

  • 在这里询问之前,至少尝试这样做。因此,对于下一个数字,它被设置为:sum1=数字/10,对于每一个其他数字,它被设置为:sum2=数字%10?否。对于第一个数字,它是
    d=数字%10。下一个数字是
    digits=digits/10;d=数字%10然后根据需要重复。你总是需要除以10,然后从商中取下一个数字。
    
    import java.util.Scanner;
    
    public class Ass. {
    
    public static void main(String[] args) {
        /*blanca 10/08/20
         * 3.Following is a fun algorithm of three steps to check whether a given 8 digit number is acceptable.
         * step1: starting from the rightmost digit,form the sum of every other digit. 
         * - For example the number is 12345658, this sum is 8+6+4+2 = 20.
         * step2: double each of the digits that were not included in the preceding step; add all digits of the resulting number. 
         * - For the example number above,doubled digits would be 10,10,6,2. Adding those digits will yield (1+0+1+0+6+2)10.
         * step3: Add the sum of the numbers in step1 and step2. if the last digit of that number is 0, the number is acceptable, not otherwise.
         * Your program should read an 8 digit number and output whether it is acceptable or not.
         */
        //declare
        int sum1 = 0;
        int sum2 = 0;
        int sum3 = 0;
        int digits = 0;
            
        Scanner data = new Scanner(System.in);
        System.out.println("Enter a card number");
        digits = data.nextInt();
        //step 1 
        sum1 = digits%10;
        // step 2
        sum2 = digits%100;
        //step 3 
        sum3 = sum1 + sum2;
        if (sum3 = 0){
            System.out.println("Acceptable");
        }
        else 
        {
            System.out.println("Unacceptable");
            }