Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ZipCode
- {
- public static int checkDigit(int zip)
- {
- int remaining = zip;
- int sum = 0;
- while (remaining > 0) {
- sum += remaining % 10;
- remaining /= 10;
- }
- return 10 - (sum % 10);
- }
- public static String digitToBarCode(int digit) {
- if (digit == 1)
- {
- return ":::||";
- }
- if (digit == 2)
- {
- return "::|:|";
- }
- if (digit == 3)
- {
- return "::||:";
- }
- if (digit == 4)
- {
- return ":|::|";
- }
- if (digit == 5)
- {
- return ":|:|:";
- }
- if (digit == 6)
- {
- return ":||::";
- }
- if (digit == 7)
- {
- return "|:::|";
- }
- if (digit == 8)
- {
- return "|::|:";
- }
- if (digit == 9)
- {
- return "|:|::";
- }
- if (digit == 0)
- {
- return "||:::";
- }
- return "";
- }
- }
- import java.util.Scanner;
- public class ZipCodeConverter
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter a zip code: ");
- int zip = input.nextInt();
- int checkDigit = checkDigit(zip);
- String digitPrint=digitToBarCode(checkDigit);
- int specificNum1=(int)((zip / Math.pow(10, 5-1)) % 10);
- String swag1=digitToBarCode(specificNum1);
- int specificNum2=(int)((zip / Math.pow(10, 4-1)) % 10);
- String swag2=digitToBarCode(specificNum2);
- int specificNum3=(int)((zip / Math.pow(10, 3-1)) % 10);
- String swag3=digitToBarCode(specificNum3);
- int specificNum4=(int)((zip / Math.pow(10, 2-1)) % 10);
- String swag4=digitToBarCode(specificNum4);
- int specificNum5=(int)((zip / Math.pow(10, 1-1)) % 10);
- String swag5=digitToBarCode(specificNum5);
- String y=swag1+swag2+swag3+swag4+swag5;
- System.out.println("|"+y+digitPrint+"|");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement