1

I want to manipulate my mother language mathematical number in Java.
Example:

int a = 1;
int b = 2;
int c = a + b;
System.out.println(c);

I want to add and show these number in my language. As in the following:

int a = ၁;
int b = ၂;
int c = a + b;
System.out.println(c);
Zabuzard
  • 25,064
  • 8
  • 58
  • 82
Nyein Chan
  • 1,215
  • 2
  • 17
  • 32
  • 1
    Why? It's generally considered bad practice to write code in anything but English. – Ingo Bürk Jul 09 '16 at 11:58
  • I don't want to write code in my language. I just want to see result in my language. – Nyein Chan Jul 09 '16 at 12:01
  • 1
    Possible duplicate of [Best way to convert English numbers to Arabic](http://stackoverflow.com/questions/11469058/best-way-to-convert-english-numbers-to-arabic) – SCouto Jul 09 '16 at 12:06
  • Related question: http://stackoverflow.com/questions/5316131/convert-string-to-another-locale-in-java But your question is broader than that, it sounds like you want to parse the code, and output selected parts of it in another language. Break the problem into separate parts, and solve each part. – T.J. Crowder Jul 09 '16 at 12:06
  • Java in itself does not understand anything else than what is defined in the Java Language Specification which does not to my knowledge mention numbers like this. Hence you must have methods which parse unicode strings containing your numbers, and which convert the result back to the numbers of your language. – Thorbjørn Ravn Andersen Jul 09 '16 at 12:26
  • You should add to your question what kind of numbering system you should use. Looking this up these seem to be from the Myanmarese Shan numbering system. You should be using a NumberFormat with the appropriate Locale to format the number, and Java 8 seems to say that it supports the "mymrshan" numbering system (http://www.oracle.com/technetwork/java/javase/java8locales-2095355.html), I can't get it to work and it doesn't seem to be part of my list of available locales ("mr_MY_u-nu-mymrshan" - I would expect that locale). So I'm not posting this as an answer, but this is how it *should* work. – Erwin Bolwidt Jul 09 '16 at 14:32
  • Of course marking this as a duplicate of a question about Arabic numerals is .. nonsensical. – Erwin Bolwidt Jul 09 '16 at 14:34

1 Answers1

1

supposed that 'a' through 'j' represent 0 to 9 in your mother language and numbers are written left to right.

it's better if you convert the input and output to normal integers and work with them. because this way you have access to all Mathematical methods that java provides and more important java's libraries are more robust than your own methods.

this two method will convert String object(your wanted characters to int) to int and Vice versa.

public  static String convertToString (int value){
    StringBuilder result = new StringBuilder();
    for (int i=1;value/i>0;i *= 10)
        switch( value % (i*10) / i){
            case 0:
                result.append('a');
                break;
            case 1:
                result.append('b');
                break;
            case 2:
                result.append('c');
                break;
            case 3:
                result.append('d');
                break;
            case 4:
                result.append('e');
                break;
            case 5:
                result.append('f');
                break;
            case 6:
                result.append('g');
                break;
            case 7:
                result.append('h');
                break;
            case 8:
                result.append('i');
                break;
            case 9:
                result.append('j');
                break;

        }

    return result.reverse().toString();
}
public  static  int convertToInt(String string){

    int result = 0;
    int j =1;
    for (int i=string.length()-1;i>=0;i--,j *= 10)
        switch(string.charAt(i)){
            case 'b':
                result += 1*j;
                break;
            case 'c':
                result += 2*j;
                break;
            case 'd':
                result += 3*j;
                break;
            case 'e':
                result += 4*j;
                break;
            case 'f':
                result += 5*j;
                break;
            case 'g':
                result += 6*j;
                break;
            case 'h':
                result += 7*j;
                break;
            case 'i':
                result += 8*j;
                break;
            case 'j':
                result += 9*j;
                break;

        }
    return result;
}