EAN-13 bar code Algorithm __ Other

Source: Internet
Author: User
/** 
 * Product Check code algorithm  
 * EAN-13 Barcode Algorithm  
 * The first 12 digits of the odd digits and C1  
 * The first 12 digits of the parity and C2  
 * will be odd and even and three times times the sum * to  
 take the result of the single digit, to 10 remainder (If the single-digit number is 0, then the checksum code is not 10, but 0)
 * @author HANMJ
/public class Eancodeutil {public
	static void Main (string[) args) {
		/*string Eancode = Eancode ("123675223432");
		System.out.println (Eancode); */
	} public
	 static String Eancode (String code) {
		 int c1=0;
		 int c2=0;
		 for (int i=0;i<code.length (); i+=2) {
			 	char c=code.charat (i);
			 	Character 
			 	int n=c-' 0 ' at position I in string code;
			 	c1+=n;//the number of odd digits and   
		 } for
		 (int i=1;i<code.length (); i+=2) {
			 char c=code.charat (i); Character
			 int n=c-' 0 ' at position I in string code;
			 c2+=n;//the number of cumulative even digits and the   
		 }
		 int cc=c1+c2*3; 
		 int check=cc%10;   
		 check= (10-cc%10)%10;
		 Code+=check+ "";
	     return code;
	}

	

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.