Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MockExam2Game {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int input = Integer.parseInt(scanner.nextLine());
- int thirdDigit = input % 10;
- int secondDigit = (input / 10) % 10;
- int firstDigit = input / 100;
- int sumDigits = thirdDigit + secondDigit + thirdDigit;
- int multiplication = firstDigit * secondDigit * thirdDigit;
- int sumTwoAndMulti = firstDigit + secondDigit * thirdDigit;
- int multiTwoAndSum = firstDigit * secondDigit + thirdDigit;
- if (sumDigits > multiplication && sumDigits > sumTwoAndMulti && sumDigits > multiTwoAndSum) {
- System.out.println(sumDigits);
- } else if (multiplication > sumDigits && multiplication > sumTwoAndMulti && multiplication > multiTwoAndSum) {
- System.out.println(multiplication);
- } else if (sumTwoAndMulti > sumDigits && sumTwoAndMulti > multiplication && sumTwoAndMulti > multiTwoAndSum) {
- System.out.println(sumTwoAndMulti);
- } else {
- System.out.println(multiTwoAndSum);
- }
- }
- }
- /*
- * Game
- Three friends came up with a game for having fun in the break between the classes.
- * One of them says a three-digit number and the others use it to form a mathematical
- * expressions by using operators for sum and multiplication between the digits of that number.
- The winner is the first one who founds the biggest number that is a result of the above mentioned rules.
- Write a program 'game', which prints out that biggest number.
- Input
- Read from the standard input
- The first line of the input will be positive three-digit number N.
- Output
- Print on the standard output
- The result should be the calculated biggest number.
- Sample tests
- Input
- 185
- Output
- 41
- Input
- 111
- Output
- 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement