Advertisement
remote87

Barcode Generator

Apr 19th, 2021
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.  
  10.         int num1 = Integer.parseInt(scan.nextLine());
  11.         int num2 = Integer.parseInt(scan.nextLine());
  12.  
  13.         int endNum = 0;
  14.         String numStr = "";
  15.  
  16.         int thousands1 = num1 / 1000;
  17.         num1 %= 1000;
  18.         int copyTh1 = thousands1;
  19.         int hundreds1 = num1 / 100;
  20.         num1 %= 100;
  21.         int copyHu1 = hundreds1;
  22.         int tens1 = num1 / 10;
  23.         int copyTe1 = tens1;
  24.         int ones1 = num1 % 10;
  25.         int copyOn1 = ones1;
  26.  
  27.         int thousands2 = num2 / 1000;
  28.         num2 %= 1000;
  29.         int hundreds2 = num2 / 100;
  30.         num2 %= 100;
  31.         int tens2 = num2 / 10;
  32.         int ones2 = num2 % 10;
  33.  
  34.         if (thousands2 % 2 == 0) thousands2--;
  35.         if (hundreds2 % 2 == 0) hundreds2--;
  36.         if (tens2 % 2 == 0) tens2--;
  37.         if (ones2 % 2 == 0) ones2--;
  38.  
  39.         endNum = Integer.parseInt("" + thousands2 + hundreds2 + tens2 + ones2);
  40.  
  41.         while (num1 < endNum) {
  42.  
  43.             if (thousands1 < thousands2 && thousands1 % 2 == 0) thousands1++;
  44.             if (hundreds1 < hundreds2 && hundreds1 % 2 == 0) hundreds1++;
  45.             if (tens1 < tens2 && tens1 % 2 == 0) tens1++;
  46.             if (ones1 < ones2 && ones1 % 2 == 0) ones1++;
  47.  
  48.             numStr = "" + thousands1 + hundreds1 + tens1 + ones1;
  49.             System.out.print(numStr + " ");
  50.  
  51.             ones1 += 2;
  52.  
  53.             if(ones1 > ones2){
  54.                 ones1 = copyOn1;
  55.                 tens1 += 2;
  56.                 if(tens1 > tens2){
  57.                     tens1 = copyTe1;
  58.                     hundreds1 += 2;
  59.                 }
  60.                 if(hundreds1 > hundreds2){
  61.                     hundreds1 = copyHu1;
  62.                     thousands1 += 2;
  63.                 }
  64.             }
  65.             num1 = Integer.parseInt(numStr);
  66.         }
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement