当前位置:网站首页>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);
}
}
边栏推荐
- Relational expression greater than > less than < congruence = = = Nan isnan() logical operator double sense exclamation point!! & |% +-- Short circuit calculation assignment expression shortcut operat
- In the future, when the interviewer asks why you don't recommend using select *, please answer him loudly!
- rust allow dead_ code
- LeetCode-栈和队列刷题
- The solution of using non root user management in secure stand-alone database under general machine environment
- 关于Aries框架增删改查-查Demo
- Do securities companies really have principal guaranteed financial products?
- go errors
- Analyze the overall planning of steam and maker education classroom
- Type de symbole
猜你喜欢

Doodle icons - a free commercial graffiti style icon library, cute, light and unique

LCD1602 - binge 51
![js传参时传入 string有数据;传入 number时没有数据;2[0]是对的!number类型数据可以取下标](/img/4e/3d0c25d9579b6d5c00473048dbbd83.png)
js传参时传入 string有数据;传入 number时没有数据;2[0]是对的!number类型数据可以取下标

Reading notes: self cultivation of programmers - Chapter 3

Detailed vector

Recommendation system topic | recommendation system architecture and single domain cross domain recall model

【HDLBits 刷题】Verilog Language(2)Vectors 部分

Analyze the overall planning of steam and maker education classroom

SSM家庭理财个人理财管理系统记账系统

Audio processing based on time-frequency diagram matlab
随机推荐
攻防世界WEB练习区(view_source、get_post、robots)
JVM initial
Relational expression greater than > less than < congruence = = = Nan isnan() logical operator double sense exclamation point!! & |% +-- Short circuit calculation assignment expression shortcut operat
Attack and defense world web practice area (backup, cookie, disabled_button)
Live800: there is nothing trivial about customer service. Don't let service destroy the reputation of the enterprise
rust allow dead_ code
Symbol類型
NumberOptional:一个字符串转数字的工具
The process of solving a bug at work
云原生讲解【扩展篇】
Symbol type
数据湖(十五):Spark与Iceberg整合写操作
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
SSM家庭理财个人理财管理系统记账系统
SSM's technical forum includes front and back offices
Liveqing live broadcast on demand streaming media OBS streaming live broadcast how to obtain interface verification token video verification streamtoken and configure token validity
Some properties of differential array operation
[interview: concurrent Article 21: multithreading: activeness] deadlock, livelock, hunger
TCP data transmission and performance
自定义kindeditor富文本默认的宽高