Advertisement
veronikaaa86

06. Barcode Generator

Dec 5th, 2021
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06BarcodeGenerator {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int startNum = Integer.parseInt(scanner.nextLine());
  10. int endNum = Integer.parseInt(scanner.nextLine());
  11.  
  12. // 2345
  13. // 6789
  14.  
  15. int startUnits = startNum % 10;
  16. int startTens = startNum / 10 % 10;
  17. int startHundreds = startNum / 100 % 10;
  18. int startThousands = startNum / 1000 % 10;
  19.  
  20. int endUnits = endNum % 10;
  21. int endTens = endNum / 10 % 10;
  22. int endHundreds = endNum / 100 % 10;
  23. int endThousands = endNum / 1000 % 10;
  24.  
  25. for (int i = startThousands; i <= endThousands; i++) {
  26. for (int j = startHundreds; j <= endHundreds; j++) {
  27. for (int k = startTens; k <= endTens; k++) {
  28. for (int l = startUnits; l <= endUnits; l++) {
  29. boolean isOdd = (i % 2 != 0)
  30. && (j % 2 != 0)
  31. && (k % 2 != 0)
  32. && (l % 2 != 0);
  33. if (isOdd) {
  34. System.out.printf("%d%d%d%d ", i, j, k, l);
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement