A company is planning to provide an extra discount to it's customers. Every order has an order ID associated with it which is a sequence of digits. The discount is calculated as the count of unique repeating digits in the order ID. Write a code to find the discount percentile given to the customers.
import java.util.Scanner;
public class App {
	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		int ID;
		System.out.print("Enter ID: ");
		ID = keyBoard.nextInt();
		System.out.println("The discount is: " + countUniqueDigits(ID) + "%");
		keyBoard.close();
	}
	static int countUniqueDigits(int ID) {
		int countUniqueDigits = 0;
		int[] digitCountArray = new int[1000];
		while (ID > 0) {
			int lastDigit = ID % 10;
			digitCountArray[lastDigit]++;
			ID = ID / 10;
		}
		for (int i = 0; i < 10; i++) {
			if (digitCountArray[i] == 1) {
				countUniqueDigits++;
			}
		}
		return countUniqueDigits;
	}
}
Comments