Advertisement
CoineTre

Game

Apr 25th, 2021
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MockExam2Game {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int input = Integer.parseInt(scanner.nextLine());
  7.         int thirdDigit = input % 10;
  8.         int secondDigit = (input / 10) % 10;
  9.         int firstDigit = input / 100;
  10.         int sumDigits = thirdDigit + secondDigit + thirdDigit;
  11.         int multiplication = firstDigit * secondDigit * thirdDigit;
  12.         int sumTwoAndMulti = firstDigit + secondDigit * thirdDigit;
  13.         int multiTwoAndSum = firstDigit * secondDigit + thirdDigit;
  14.         if (sumDigits > multiplication && sumDigits > sumTwoAndMulti && sumDigits > multiTwoAndSum) {
  15.             System.out.println(sumDigits);
  16.         } else if (multiplication > sumDigits && multiplication > sumTwoAndMulti && multiplication > multiTwoAndSum) {
  17.             System.out.println(multiplication);
  18.         } else if (sumTwoAndMulti > sumDigits && sumTwoAndMulti > multiplication && sumTwoAndMulti > multiTwoAndSum) {
  19.             System.out.println(sumTwoAndMulti);
  20.         } else {
  21.             System.out.println(multiTwoAndSum);
  22.         }
  23.     }
  24. }
  25. /*
  26. * Game
  27.  
  28. Three friends came up with a game for having fun in the break between the classes.
  29. *  One of them says a three-digit number and the others use it to form a mathematical
  30. * expressions by using operators for sum and multiplication between the digits of that number.
  31.  
  32. The winner is the first one who founds the biggest number that is a result of the above mentioned rules.
  33.  
  34. Write a program 'game', which prints out that biggest number.
  35. Input
  36.  
  37. Read from the standard input
  38.  
  39.     The first line of the input will be positive three-digit number N.
  40.  
  41. Output
  42.  
  43. Print on the standard output
  44.  
  45.     The result should be the calculated biggest number.
  46.  
  47. Sample tests
  48. Input
  49.  
  50. 185
  51.  
  52. Output
  53.  
  54. 41
  55.  
  56. Input
  57.  
  58. 111
  59.  
  60. Output
  61.  
  62. 3
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement