Answer to Question #274621 in Java | JSP | JSF for Akhil

Question #274621

An e-commerce company plans to give their customers a discount for the Christmas holiday. The discount will be calculated on the basis of the bill amount of the order placed. The discount amount is the product of the sum of all odd digits and the sum of all even digits of the customer’s total bill amount. Write an algorithm to find the discount amount for the given total bill amount.InputThe input consists of an integer billAmount, representing the total bill amount of a customer.OutputPrint an integer representing the discount amount for the given total bill.ConstraintsO <billAmount≤ 109ExampleInput:2514795Output:162Explanation:Odd digits in the given number 2514795 are 5, 1, 7, 9, 5. The sum of these odd digits is 27.Even digits in the given number 2514795 are 2, 4. The sum of these even digits is 6.So, the output is 162

1
Expert's answer
2021-12-02T07:31:03-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);
		System.out.print("Enter the number 1: ");
		int billAmount = keyBoard.nextInt();


		
		int sumEvenDigits = 0;
		int sumOddDigits = 0;
		while (billAmount != 0) {
			int d =  billAmount % 10;
			if (d % 2 == 0) {
				sumEvenDigits += d;
			} else {
				sumOddDigits += d;
			}
			billAmount = billAmount / 10;
		}
		int discountAmount = sumEvenDigits*sumOddDigits;
		System.out.println(discountAmount);
		keyBoard.close();
	}
}

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