I can't complete 4th requirement - The min method must return the minimum of the 5 passed numbers. If there are several minimum numbers, return any of them.
Not sure what I'm missing...
package com.codegym.task.task05.task0531;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Improving functionality
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(reader.readLine());
int b = Integer.parseInt(reader.readLine());
int c = Integer.parseInt(reader.readLine());
int d = Integer.parseInt(reader.readLine());
int e = Integer.parseInt(reader.readLine());
int minimum = min(a, b, c, d, e);
System.out.println("Minimum = " + minimum);
}
public static int min(int a, int b, int c, int d, int e) {
int minNum;
minNum = a;
if(minNum>b)
return b;
else if (minNum >c)
return c;
else if(minNum>d)
return d;
else if(minNum>e)
return e;
else
return a;
}
}
Not sure what is missing.
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Przemysław Dr
12 August 2019, 19:52
Hi,
have you checked it on real numbers?
Let assume number: 3, 1, 0, 5, 2. Your code will return 1 instead of 0... You are returning b without comparing it to the d and e.
P.S. Use the "code" option when pasting the code to the forum.
0