Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Energy {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- int digit = 0;
- int sumOdd = 0;
- int sumEven = 0;
- int length = String.valueOf(n).length();
- //calculate the sum of the even and odd numbers separately
- while (n > 0 && length <= 18) {
- digit = n % 10;
- if (digit % 2 == 0 || digit == 0) {
- sumEven += digit;
- } else if (digit % 2 == 1 || digit == 1) {
- sumOdd += digit;
- }
- n -= digit;
- n /= 10;
- }
- /*
- if (sumOdd > sumEven) {
- System.out.printf("%.0f cups of coffee", sumOdd);
- } else if (sumEven > sumOdd) {
- System.out.printf("%.0f energy drinks", sumEven);
- } else {
- System.out.printf("%.0f of both", sumEven);
- }
- */
- if (sumOdd > sumEven) {
- System.out.printf(sumOdd + " cups of coffee");
- } else if (sumEven > sumOdd) {
- System.out.printf(sumEven + " energy drinks");
- } else {
- System.out.printf(sumEven + " of both");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement