Answer to Question #250333 in Java | JSP | JSF for Pranith

Question #250333
a company is planning a big sale at which they will give their customers a special promotional discount. each customer that purchases a product from the company has a unique customer id numbered from 0 to n-1.

1.andy, the marketing head of the company, has selected bill amounts of the n customers for the promotional scheme. the discount will be given to the customers whose bill amounts are perfect squares. the customers may use this discount on a future purchase. write an algorithm to help andy find the number of customers that will be given discounts?
1
Expert's answer
2021-10-13T00:29:09-0400
public class Main {
    public static void selectForDiscount(int[] billsAmount) {
        for (int i = 0; i < billsAmount.length; i++) {
            for (int j = 0; j < billsAmount[i] / 2; j++) {
                if (j * j == billsAmount[i]) {
                    System.out.println(i);
                }
            }
        }
    }

    public static void main(String[] args) {
        selectForDiscount(new int[]{5, 1, 0, 9, 15, 25, 65, 78, 100});
    }
}

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