Got a task where I am supposed to add a function that returns a minimum from 5 passed integers. I implemented it, it works but it doesnt pass the testing. Heres the code. "minimumFive" is the function I was supposed to add.

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);
    int minimumFive = minFive(a,b,c,d,e);
    System.out.println("Minimum = " + minimum);
    System.out.println("MinimumFive = " + minimumFive);
}

public static int min(int a, int b)
{
    return a < b ? a : b;
}

public static int minFive(int a, int b, int c,int d,int e) {
    if(min(a,b) < min(c,d) ) {
        return(min(min(a,b),e));
    } else {
        return(min(min(c,d),e));
    }
}

}

asked 28 Jul '17, 12:41

Flashie's gravatar image

Flashie
152
accept rate: 0%


Try to add result to first sout and delete the second. Instead of:

 int minimum = min(a, b);
int minimumFive = minFive(a,b,c,d,e);
System.out.println("Minimum = " + minimum);
System.out.println("MinimumFive = " + minimumFive);

leave:

int minimumFive = minFive(a,b,c,d,e);
System.out.println("Minimum = " + minimumFive);
link

answered 28 Jul '17, 12:49

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

It passed. Thank you!

(28 Jul '17, 13:39) Flashie

This is another solution, but not passing tests..

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[] myArray = new int[5];
        myArray[0] = a;
        myArray[1] = b;
        myArray[2] = c;
        myArray[3] = d;
        myArray[4] = e;

        Arrays.sort(myArray);
        System.out.println(myArray[0]);
    }
}
link

answered 17 Apr, 15:05

labamba's gravatar image

labamba
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15

Asked: 28 Jul '17, 12:41

Seen: 455 times

Last updated: 17 Apr, 15:05