This is my code
It says the variable m might not have been initialized, but when I try to initialize it with 0 or -2147483648 the number I initialize it with is what it returns. It's like it ignores calling min method. I'm lost.
-------------------
/*
Minimum of three numbers
*/
public class Solution {
public static int min(int a, int b, int c) {
int m;
if(a<=b && a<=c)
{
a = m;
}
else if(b<=c && b<=a)
{
b = m;
}
else if(c<=a && c<=b)
{
c = m;
}
return m;
}
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(5, 5, 10));
}
}
Code isn't compiling - https://codegym.cc/tasks/com.codegym.task.task02.task0216
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Shuy
8 January 2020, 07:21
Youre trying to assign the value of m to a, b, or c, while it should probably be the other way around.
0