Advertisement
Azazavr

javarush.test.level05.lesson12.bonus02

Nov 1st, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package com.javarush.test.level05.lesson12.bonus02;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5.  
  6. /* Нужно добавить в программу новую функциональность
  7. Задача: Программа вводит два числа с клавиатуры и выводит минимальное из них на экран.
  8. Новая задача: Программа вводит пять чисел с клавиатуры и выводит минимальное из них на экран.
  9. */
  10.  
  11. public class Solution
  12. {
  13.  
  14.     public static void main(String[] args) throws Exception
  15.     {
  16.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  17.         int a = Integer.parseInt(reader.readLine());
  18.         int b = Integer.parseInt(reader.readLine());
  19.         int c = Integer.parseInt(reader.readLine());
  20.         int d = Integer.parseInt(reader.readLine());
  21.         int e = Integer.parseInt(reader.readLine());
  22.  
  23.         int minimum = min(a, b);
  24.         int minimum2 = minThree(c, d, e);
  25.  
  26.         //Очень корявое решение.
  27.         if (minimum < minimum2)
  28.         System.out.println("Minimum = " + minimum);
  29.         else
  30.         System.out.println("Minimum = " + minimum2);
  31.     }
  32.    
  33.     public static int min(int a, int b)
  34.     {
  35.         return a < b ? a : b;
  36.     }
  37.     public static int minThree(int c, int d, int e)
  38.     {
  39.         int min=0;
  40.         if (c < d && c < e)
  41.             min = c;
  42.         else if (d < c && d < e)
  43.             min = d;
  44.         else if (e < c && e < d)
  45.             min = e;
  46.         return min;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement