当前位置:网站首页>Generate 13 bit barcode
Generate 13 bit barcode
2022-07-24 02:55:00 【Chihiro~~】
13 Bit barcode rules : The thirteenth digit is the check code calculated from the first twelve digits .
for example :690123456789( front 12 For random generation , Get the second 13 position )
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
The basic idea :
Random generation 12 A digital , To store in the array . According to the requirements given in the title, find the 13 position , Put the obtained No 13 The bit check code is stored in the last bit of the array . Then print out the array .
Code :
import java.util.Random;
public class Exer {
public static void main(String[] args) {
Random random = new Random();
int[] arr = new int[13];// Define a length of 13 Array of
int oddSum = 0;// Odd digits and
int evenSum = 0;// Even digit sum
System.out.print(" Input 12 Bit barcode is :");
for(int i = 0; i < 12; i++) {
arr[i] = random.nextInt(10);// Store the randomly generated number in the array
System.out.print(arr[i]);
if(i % 2 == 0) {
oddSum += arr[i];
}else {
evenSum += arr[i];
}
}
System.out.println();
int sum = oddSum + evenSum * 3;// Add three times of odd and even sums
int ge = sum % 10;// The single digits of the result of adding odd sum and triple of even sum
System.out.print(" The returned barcode with verification code is :");
for(int i = 0; i < arr.length; i++) {
if(ge == 0) {
arr[arr.length] = 0;
}else {
arr[arr.length-1] = 10 - ge;
}
System.out.print(arr[i]);
}
}
}
边栏推荐
- Job hunting and recruitment system of SSM part-time job hunting
- js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
- Wonderful! The description of meituan Octo distributed service management system is too clear
- I'm a novice. I heard that there is a breakeven financial product in opening an account. What is it?
- Unity 消息推送
- Why use the well architected framework?
- Analyze the space practice field required by maker education activities
- Jparepository extension interface
- JVM初始
- C language exercises
猜你喜欢

Ugui source code analysis - maskablegraphic

Diversity of SIGIR '22 recommendation system papers

Composition API (in setup) watch usage details
[email protected]使用原理"/>(六)装饰器扩展之[email protected]使用原理

UIE: 信息抽取的大一统模型

Interpretation of steam education with the deepening of educational reform

Ugui source code analysis - stencilmaterial
![[management / upgrade] * 02. View the upgrade path * FortiGate firewall](/img/c7/da6db46d372e7462cd14852b662d6d.png)
[management / upgrade] * 02. View the upgrade path * FortiGate firewall

PMP preparation experience | good habits, good process, good results

Liveqing live broadcast on demand streaming media OBS streaming live broadcast how to obtain interface verification token video verification streamtoken and configure token validity
随机推荐
The simple use of ADB command combined with monkey is super detailed
Jparepository extension interface
AcWing 4499. 画圆 (相似三角形)
The process of solving a bug at work
7月开发过程中遇到的问题总结
Open source quantum development framework cirq
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
通用机环境下安全版单机数据库使用非root用户管理的解决方案
Mysql database, query
[hdlbits questions] Verilog language (2) vectors
Make life full of happiness
[interview: concurrent Article 21: multithreading: activeness] deadlock, livelock, hunger
JpaRepository扩展接口
Ugui source code analysis - stencilmaterial
Acwing 4499. draw a circle (similar to a triangle)
508. The subtree element with the most occurrences and the pure C implementation of hash table method
(6) Decorator extension [email protected] Principle of use
Example of producer consumer code implemented by the destructor framework without lock
记于2022.7.21
LeetCode-栈和队列刷题