Answer to Question #303470 in Java | JSP | JSF for Mansi

Question #303470

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-02-28T01:06:20-0500
public class Main {
    public static int getDiscount(String id) {
        int[] counts = new int[10];
        int discount = 0;
        for (int i = 0; i < id.length(); i++) {
            counts[id.charAt(i) - '0']++;
        }
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] > 1) {
                discount++;
            }
        }
        return discount;
    }

}

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
APPROVED BY CLIENTS