当前位置:网站首页>Rules for generating 13 digit barcode EAN-13 Code: the thirteenth digit is the verification code obtained by calculating the first twelve digits.
Rules for generating 13 digit barcode EAN-13 Code: the thirteenth digit is the verification code obtained by calculating the first twelve digits.
2022-07-24 02:55:00 【Quarter seventeen】
subject
Generate 13 Bit barcode
Ean-13 Code rule : The thirteenth digit is the check code calculated from the first twelve digits .
for example :690123456789
The process of calculating its check code is :
@ The odd sum of the first twelve digits 6+0+2+4+6+8=26
@ The sum of the even digits of the first twelve 9+1+3+5+7+9=34
@ Add three times the sum of odd and even numbers 26+34*3=128
@ Take the single digit of the result :128 The single digit of is 8
@ use 10 Subtract this single digit 10-8=2
So the check code is 2
( notes : If the single digit of the result is 0, Then the check code is not 10(10-0=10), It is 0)
Implementation method ean13() Calculate the verification code , Input 12 Bit bar code , Return the barcode with verification code .
example : Input :692223361219 Output :6922233612192
Code
import java.util.Scanner;
public class Demo00 {
public static void main(String[] args) {
System.out.println(" Please enter 12 digits as barcode ");
Scanner sc = new Scanner(System.in);
long number = sc.nextLong();
long number2 = number;
long[] array = new long[12];
for (int i = 0; i < 12; i++) {
array[i] = number % 10;
number /= 10;
}
int oddSum = 0;// Odd number
int evenSum = 0;// even numbers
// Odd and
for (int i = 0; i < 12; i = i + 2) {
oddSum += array[i];
}
// Even and
for (int j = 1; j < 12; j = j + 2) {
evenSum += array[j];
}
int threeSum = oddSum * 3 + evenSum;
int geWei = threeSum % 10;
int jiaoYan = 0;
if (geWei != 0)// Judge whether it is 0 Not by 10 reduce It's the same
jiaoYan = 10 - geWei;
long number3 = number2 * 10 + jiaoYan;
System.out.println(number3);
}
}
边栏推荐
- Attack and defense world web practice area (weak_auth, simple_php, xff_referer)
- js传参时传入 string有数据;传入 number时没有数据;2[0]是对的!number类型数据可以取下标
- NumberOptional:一个字符串转数字的工具
- summernote 字体显示中文
- ssm的求职招聘系统兼职应聘求职
- Custom log annotation, request fetching
- Unity Message push
- Attack and defense world web practice area (webshell, command_execution, simple_js)
- An introductory example of structure and combinatorial ideas in go language
- [hdlbits questions] Verilog language (2) vectors
猜你喜欢

Ugui source code analysis - stencilmaterial

ssm的求职招聘系统兼职应聘求职

【HDLBits 刷题】Verilog Language(2)Vectors 部分
![Cloud native explanation [expansion]](/img/82/b206d496cfecd61aedd53ebc6ae1ea.png)
Cloud native explanation [expansion]

Ugui source code analysis - Mask

Recorded on July 21, 2022

Example of producer consumer code implemented by the destructor framework without lock

Understand the low code implementation of microservices

Honey, we are homeless now

Summernote rich text editor
随机推荐
Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
JVM初始
SSM家庭理财个人理财管理系统记账系统
AcWing 4498. 指针 (DFS)
攻防世界WEB練習區(view_source、get_post、robots)
通用机环境下安全版单机数据库使用非root用户管理的解决方案
go errors
kettle
如何获取步态能量图gei
Go IO operation - file read
Mysql database, sorting and single line processing functions
C language exercises
go IO操作-文件写
La chaîne entrante a des données lors de la transmission des paramètres JS; Aucune donnée n'a été transmise au numéro; 2 [0] Oui! Les données de type numéro peuvent être indexées
AcWing 4499. 画圆 (相似三角形)
JpaRepository扩展接口
Summernote supports custom video upload function
Detailed vector
【英雄哥七月集训】第 23天: 字典树
Symbol類型