Here is my code:

public class Solution { public static int min(int a, int b, int c) { int m2; if(a<b) m2 = a; else m2 = b; return m2; }

public static void main(String[] args) throws Exception
{
    int a = -3, b = -2, c = -1;
    int m = min(a,b,c);
    System.out.println("Minimum is " + m);
}

}

Here is what javarush is telling me about that:

✓ The program is compiled without errors. ✗ The program runs correctly but it has not pass testing. This is program output during runtime:

Minimum is -3

Please help!

asked 08 Aug '17, 15:15

endrju69's gravatar image

endrju69
112
accept rate: 0%


12next »

You forget about c. You must compare m2 with c.

link

answered 09 Aug '17, 09:30

genek's gravatar image

genek
175
accept rate: 0%

edited 09 Aug '17, 09:30

public static void main(String[] args) throws Exception { int a = -3, b = -2, c = -1; int m = min(a,b,c); System.out.println("Minimum is " +m);

}
public static int min(int a, int b, int c)
{
    int m2;
    if(a<c)
    m2 = a;
    else
    m2 = c;
    return m2;
     }

}

What about now?

"Yup! It seems that you forgot that the numbers can also be negative. This is studied in elementary school. You have excuse only if you are from kindergarten: P Check how your program works on negative numbers."

(09 Aug '17, 11:07) endrju69

public class Solution { public static int min(int a, int b, int c) {

    if(a<b && b<c)
    return a;
    if(b<a && b<c)
    return b;
    else
    return c;
}

public static void main(String[] args) throws Exception
{
    System.out.println( min(1,2,3) );
    System.out.println( min(-1,-2,-3) );
    System.out.println( min(3,5,3) );
    System.out.println( min(10,5,10) );
}

}

result: ✓ The program is compiled without errors. ✗ The program runs correctly but it has not pass testing. This is program output during runtime:

1 -3 3 5

link

answered 09 Aug '17, 11:54

endrju69's gravatar image

endrju69
112
accept rate: 0%

 if(a<b && b<c)

What if b == c? Program won't execute code because test evaluates to false.

A must be smaller than b and smaller than c. It doesn't matter whether b is smaller than c or not.

link

answered 11 Aug '17, 03:29

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 11 Aug '17, 03:30

Thank you! Now it works fine.

link

answered 11 Aug '17, 06:20

endrju69's gravatar image

endrju69
112
accept rate: 0%

  1. public class Solution
  2. {
  3. public static int min(int a, int b, int c)
  4. {
  5. //add your code here
  6. if (a<=b && a<=c) return a;
  7. if (b<а && b<с) return b;
  8. else return c;
  9. }
  10. public static void main(String[] args) throws Exception
  11. {
  12. System.out.println( min(1,2,3) );
  13. System.out.println( min(-1,-2,-3) );
  14. System.out.println( min(3,5,3) );
  15. System.out.println( min(10,5,10) );
  16. }
  17. }
link

answered 28 Oct '17, 11:26

Winnermann's gravatar image

Winnermann
111
accept rate: 0%

Right solution here

int result = 0;

    if(a<b && a<=c) result=a;

    if(b<a && b<c) result=b;

    if(c<a && c<b ) result=c;

    return result;
link

answered 03 Jan, 08:58

Alhunah's gravatar image

Alhunah
11
accept rate: 0%

edited 03 Jan, 08:59

package com.javarush.test.level02.lesson08.task03;

/ Minimum of three numbers Write a function that returns a minimum of three numbers. / public class Solution { public static int min(int a, int b, int c) { //add your code here if (a < b && a<c) return a; else if (b<a && b<c) return b; else return c; }

public static void main(String[] args) throws Exception
{
    System.out.println( min(1,2,3) );
    System.out.println( min(-1,-2,-3) );
    System.out.println( min(3,5,3) );
    System.out.println( min(10,5,10) );
}

}

link

answered 05 Jan, 09:48

%D0%A0%D0%B0%D0%BA%D0%B8%D1%88's gravatar image

Ракиш
1
accept rate: 0%

package com.javarush.test.level02.lesson08.task03;

/ Minimum of three numbers Write a function that returns a minimum of three numbers. / public class Solution { public static int min(int a, int b, int c) { //add your code here if (a < b && a<c) return a; else if (b<a && b<c) return b; else return c; }

public static void main(String[] args) throws Exception
{
    System.out.println( min(1,2,3) );
    System.out.println( min(-1,-2,-3) );
    System.out.println( min(3,5,3) );
    System.out.println( min(10,5,10) );
}

}

link

answered 05 Jan, 09:49

%D0%A0%D0%B0%D0%BA%D0%B8%D1%88's gravatar image

Ракиш
1
accept rate: 0%

if (a<b && a<c) return a; elseif (b<a && b<c) return b; else return c;

link

answered 18 Jan, 07:58

MASTER%20RELAXa's gravatar image

MASTER RELAXa
111
accept rate: 0%

if (a<b && a<c) return a;
elseif (b<a && b<c) return b;
else return c;
link

answered 18 Jan, 07:58

MASTER%20RELAXa's gravatar image

MASTER RELAXa
111
accept rate: 0%

edited 18 Jan, 07:59

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:

×79
×53
×17

Asked: 08 Aug '17, 15:15

Seen: 1,898 times

Last updated: 08 Nov, 16:30