Answer to Question #286988 in Java | JSP | JSF for Eren

Question #286988

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.

1
Expert's answer
2022-01-12T09:56:50-0500


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;
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog