English 中文(简体)
Java的编码
原标题:Encoding codes in Java

过去几个星期里,一夫通过以下书读:。 Error Control Coding: Fundamentals and Applications in order to Learning about BCH (Bose, Chaudhuri, Hocquenghem) 在电信公司担任初级节目制作职务的守则。

这本书主要涵盖该主题背后的数学和理论,但我竭力执行某些概念;主要取下个“<>n>/em>密码。 我有一份全球倡议(通过Net Beans执行,因此,由于档案是巨大的,我赢得了该守则的帽子),该守则通过一部法律,以获得下一个n号:

产生这些数字是我遇到问题的。 如果我能够把所有这些工作纳入到仅仅依赖编码方法中,而不是通过使用《全球倡议》,那么我的生活就会更加容易十倍。

几天来,这一直令我cra笑,因为从投入中产生数千 000 000美元是容易的,但我失去了从那里获得我守则的去向。 然后我做些什么来创造下一个工作数目?

如能帮助制定上述守则,将不胜感激。

最佳回答

(big edit...) 采用该守则似乎更可行:

import java.util.ArrayList;
import java.util.List;


public class Main
{
    public static void main(final String[] argv)
    {
        final int startValue;
        final int iterations;
        final List<String> list;

        startValue = Integer.parseInt(argv[0]);
        iterations = Integer.parseInt(argv[1]);
        list = encodeAll(startValue, iterations);
        System.out.println(list);
    }

    private static List<String> encodeAll(final int startValue, final int iterations)
    {
        final List<String> allEncodings;

        allEncodings = new ArrayList<String>();

        for(int i = 0; i < iterations; i++)
        {
            try
            {
                final int    value;
                final String str;
                final String encoding;

                value = i + startValue;
                str = String.format("%06d", value);
                encoding = encoding(str);
                allEncodings.add(encoding);
            }
            catch(final BadNumberException ex)
            {
                // do nothing
            }
        }

        return allEncodings;
    }

    public static String encoding(String str)
        throws BadNumberException
    {
        final int[]         digit;
        final StringBuilder s;

        digit = new int[10];

        for(int i = 0; i < 6; i++)
        {
            digit[i] = Integer.parseInt(String.valueOf(str.charAt(i)));
        }

        digit[6] = ((4*digit[0])+(10*digit[1])+(9*digit[2])+(2*digit[3])+(digit[4])+(7*digit[5])) % 11;
        digit[7] = ((7*digit[0])+(8*digit[1])+(7*digit[2])+(digit[3])+(9*digit[4])+(6*digit[5])) % 11;
        digit[8] = ((9*digit[0])+(digit[1])+(7*digit[2])+(8*digit[3])+(7*digit[4])+(7*digit[5])) % 11;
        digit[9] = ((digit[0])+(2*digit[1])+(9*digit[2])+(10*digit[3])+(4*digit[4])+(digit[5])) % 11;

        // Insert Parity Checking method (Vandermonde Matrix)
        s = new StringBuilder();

        for(int i = 0; i < 9; i++)
        {
            s.append(Integer.toString(digit[i]));
        }

        if(digit[6] == 10 || digit[7] == 10 || digit[8] == 10 || digit[9] == 10)
        {
            throw new BadNumberException(str);
        }

        return (s.toString());
    }
}

class BadNumberException
    extends Exception
{
    public BadNumberException(final String str)
    {
        super(str + " cannot be encoded");
    }
}

我倾向于放弃这一例外,而不是回到一种特殊的扼杀。 在本案中,我忽视了我通常说是不良做法的例外,但我认为这是你想要的。

问题回答

很难说,如果我回答问题,但在阅读你的问题之后,也许会想到:

public List<String> encodeAll() {
  List<String> allEncodings = new ArrayList<String>();
  for (int i = 0; i < 1000000 ; i++) { 
    String encoding = encoding(Integer.toString(i));
    allEncodings.add(encoding);
  }
  return allEncodings;
}

解决办法存在一个缺陷,结点结果不是零增长。 如果是你想要的话,我建议在编码呼吁中使用<条码>String.format(”<something> i。

<>Update>

在你目前的呼吁中,用这种方法取代要求编码。 您收到一份附有所有编码的定单。

我假定,你只是对占领价值感兴趣——我的错误,现在我认为你只是想想像你那样放弃价值000009的编码,从而消除了令人难以置信的占领。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签