简体   繁体   English

Android找不到数字

[英]Android finding missing numbers

I am developing an Android Application.. which is a numerology app. 我正在开发一个Android应用程序..这是一个数字命理应用程序。 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. 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. 例如我的名字是ROSHAN,我的值是R-9,O - 6,S - 1,H - 8,A - 1,N - 5.所以当IU计算所有这些值时9 + 6 + 1 + 8 + 1 +5 = 30 = 3 + 0 = 3.所以我的价值是三。 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.. 我为此做了代码,我正在为缺少的数字开发代码,比如在我的名字中缺少数字是2,3,4,7 ..任何人都可以帮助我..我给的代码到目前为止我开发了..

MainActivity.java 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. 使用array of boolean来指示是否使用该数字。

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 )
   {
   ...
   ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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