Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Chinese Remainder therom

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Chinese Remainder therom

     try {
             CH_m = new BigInteger(Chinese_m.getText());
             CH_n = new BigInteger(Chinese_n.getText());
             CH_a = new BigInteger(Chinese_a.getText());
             CH_b = new BigInteger(Chinese_b.getText());
             } catch(Exception ex){
               if(Chinese_m.getText().isEmpty() || Chinese_n.getText().isEmpty() || Chinese_a.getText().isEmpty() || Chinese_b.getText().isEmpty()){
                   JOptionPane.showMessageDialog(Chinese_m, "Please fill form complete");
               } else {
                   JOptionPane.showMessageDialog(Chinese_m, "Please type number ONLY!"); //pop up a message if the user type anything expect number
               }
            }
             CH_d = CH_n.modInverse(CH_m); //inverse n modulo n
             display.setText(CH_d.toString());
     
             CH_ab = CH_a.subtract(CH_b); //a-b
             CH_k = (CH_ab.multiply(CH_d)).mod(CH_m); //k=(a-b)i(mod m)
             CH_ans_x = CH_b.add((CH_n.multiply(CH_k))); //x=b+nk
     
             Chinese_k.setText(Chinese_k.getText()+"k: "+CH_k);
             Chinese_Ans_x.setText(Chinese_Ans_x.getText()+"x: "+CH_ans_x);
     
             display.setText(display.getText()+"\ninverse: "+CH_n+" modulo "+CH_m+" is "+CH_d); //d = s+t
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"K =(a-b)i(mod m)");
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"Substitute i = "+CH_d);
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"K = ("+CH_a+" - "+CH_b+") "+CH_d+" (mod "+CH_m+")"); //output ans of inverse n modulo n
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"K = "+CH_k); //output of k=(a-b)i(mod m)
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"x= b + nk");
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"Substitute k = "+CH_k); //output ans k
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"x = "+CH_b+" + ("+CH_n+")("+CH_k+")"); //output of x=b+nk
             display.setText(display.getText()+"\n"); //NEXT LINE
             display.setText(display.getText()+"x = "+CH_ans_x+"\n"); //output ans x
             /*
             if (value1.compareTo(value2)== a)//a is either 0, 1 or -1
             * ==0 value1 equal to value2
             * ==1 value1 more than value2
             * ==-1 value1 less than value2
             */
             if (CH_ans_x.mod(CH_m).compareTo(CH_a.mod(CH_m)) == 0 ) {
                display.setText(display.getText()+CH_ans_x+" ≡ "+CH_a+"(mod "+CH_m+")");
                display.setText(display.getText()+" [True]");
             }
             else{
                display.setText(display.getText()+CH_ans_x+" ≡ "+CH_a+"(mod "+CH_m+")");
                display.setText(display.getText()+" [False]");
             }
             if (CH_ans_x.mod(CH_n).compareTo(CH_b.mod(CH_n)) == 0) {
                display.setText(display.getText()+"\n"+CH_ans_x+" ≡ "+CH_b+"(mod "+CH_n+")");
                display.setText(display.getText()+" [True]");
             }
             else{
                display.setText(display.getText()+"\n"+CH_ans_x+" ≡ "+CH_b+"(mod "+CH_n+")");
                display.setText(display.getText()+" [False]");
             }

    how come when i type a=2,b=2,m=2,n=2. the output did not come out.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,094
    Thanks
    48
    Thanked 2,152 Times in 2,125 Posts

    Default Re: Chinese Remainder therom

    how come when i type a=2,b=2,m=2,n=2. the output did not come out.
    Try debugging the code by adding printlns to show the variables values as they change and the execution flow.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chinese Remainder therom

    Quote Originally Posted by Norm View Post
    Try debugging the code by adding printlns to show the variables values as they change and the execution flow.
    Thanks for the help

Similar Threads

  1. how to read chinese data from excel to java
    By swapna in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 17th, 2011, 06:02 AM
  2. Replies: 1
    Last Post: April 7th, 2011, 07:01 AM
  3. Vietnamese Character Problem in JSP Report. Chinese and Thai Char OK
    By mrvora in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: October 23rd, 2009, 02:35 AM
  4. Certain Chinese Characters not displayed properly.
    By kerwintang in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 20th, 2009, 08:23 AM