Advertisement
Guest User

Sum of greatest and smallest

a guest
May 7th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P7SumOfGreatestAndSmallest {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String inputNum1 = scanner.nextLine();
  8. int num1 = Integer.parseInt(inputNum1);
  9.  
  10. String inputNum2 = scanner.nextLine();
  11. int num2 = Integer.parseInt(inputNum2);
  12.  
  13. String inputNum3 = scanner.nextLine();
  14. int num3 = Integer.parseInt(inputNum3);
  15.  
  16. //using if statement and logical comparison to find the min and max value
  17.  
  18. if (num1 >= num2 && num2 >= num3) {
  19. System.out.println(num1 + num3);
  20. }
  21. if (num1 >= num3 && num3 >= num2) {
  22. System.out.println(num1 + num2);
  23. }
  24. if (num2 >= num1 && num1 >= num3) {
  25. System.out.println(num2 + num3);
  26. }
  27. if (num2 >= num3 && num3 >= num1) {
  28. System.out.println(num2 + num1);
  29. }
  30. if (num3 >= num1 && num1 >= num2) {
  31. System.out.println(num3 + num2);
  32. }
  33. if (num3 >= num2 && num2 >= num1) {
  34. System.out.println(num3 + num1);
  35. }
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement