简体   繁体   中英

Android finding missing numbers

I am developing an Android Application.. which is a numerology app. In which the value of calculating the name is doing . A, J, S – 1 B, K, T – 2 C, L, U – 3 D, M, V – 4 E, N, W – 5 F, O, X – 6 G, P, Y – 7 H, Q, Z – 8 I, R – 9.

This is the value of each letter. When user enter the name his value is calculated and display the result. I developed the code for calculating the value. But now I need to calculate the missing numbers. For example my name is ROSHAN and my value is R-9, O - 6, S - 1, H - 8, A - 1, N - 5. so when IU calculate all these values 9+6+1+8+1+5 = 30 = 3+ 0 = 3. So my value is three. I did the code for that, I am developing code for the missing numbers like in my name missing numbers is 2,3,4,7 .. can anyone help me.. I am giving the code so far I developed..

MainActivity.java

long sum70 = 0;
        long sum80 = 0;
        long sum90 = 0
sum70 = getsum70(et7.getText().toString());
        sum80 = getSum80(et8.getText().toString());
        sum90 = getSum90(et9.getText().toString());
private long getsum70(String text) {
        // TODO Auto-generated method stub
        long sum70 = 0;
        char[] name70 = new char[text.length()];

               name70 = text.toCharArray();

               for(int i=0; i<text.length(); i++)
               {
                   sum70 += value70( name70[i] );
                }
                 //while (sum10>9)

              while (sum70>9 )
               {                  


                   sum70 = findDigitSum70(sum70);

               }
        return sum70;
    }


    private long value70(char a) {
        // TODO Auto-generated method stub
        switch(a)
    {
       case 'A': 
       return 1;    
       case 'B':
       return 2;
       case 'C':
       return 3;
       case 'D':
       return 4;
       case 'E':
       return 5;
       case 'F':
       return 6;
       case 'G':
       return 7;
       case 'H':
       return 8;
       case 'I':
       return 9;
       case 'J':
       return 1;
       case 'K':
       return 2;
       case 'L':
       return 3;
       case 'M':
       return 4;
       case 'N':
       return 5;
       case 'O':
       return 6;
       case 'P':
       return 7;
       case 'Q':
       return 8;
       case 'R':
       return 9;
       case 'S':
       return 1;          
       case 'T':
       return 2;
       case 'U':
       return 3;
       case 'V':
       return 4;
       case 'W':
       return 5;
       case 'X':
       return 6;
       case 'Y':
       return 7;
       case 'Z':
       return 8;
       default:         
       return 0;

    }
    }

    private long findDigitSum70(long n) {
        // TODO Auto-generated method stub
        int sum70=0;
        while (n != 0) 
        {
         sum70 += n % 10;
         n = n / 10;
        }
        return sum70;
    }

Use an array of boolean to indicate whether the number is used or not.

Example:

private List<Integer> getMissingNo(String text){
    ArrayList<Integer> missingNo = new ArrayList<Integer>();

    boolean[] usedNos = new boolean[9];
    for(int i=0; i<text.length(); i++){
        usedNos [value70(text.charAt(i))-1] = true;
    }

    for(int i=0; i<9; i++){
        if(!usedNos[i]){
            missingNo.add(i+1);
            System.out.println((i+1) + " is missing");
        }
    }

    return missingNo;
}

Update your code as follows:

    ...
    ...
    name70 = text.toCharArray();

    boolean[] numbers = new boolean[9];
    for(int i=0; i<text.length(); i++)
    {
        int number = value70(name70[i]);
        numbers[number] = true;
        sum70 += number;
    }

    for (int i = 1; i < numbers.length; i++) {
        if (!numbers[i]) {
            // numbers[i] this is a missing number
            // print numbers[i]
        }
    }

   while (sum70>9 )
   {
   ...
   ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM