31st Oct 2021, 9:21 AM
STOP
STOP - avatar
9 Answers
+ 3
public not a pubilc
31st Oct 2021, 9:33 AM
Galstyan
Galstyan - avatar
+ 1
But the code doesn't work correctly
31st Oct 2021, 9:35 AM
Galstyan
Galstyan - avatar
31st Oct 2021, 9:43 AM
Galstyan
Galstyan - avatar
+ 1
What do you need according to the program? Count the smallest of the two numbers? Why min is equal to 0?
31st Oct 2021, 9:48 AM
Galstyan
Galstyan - avatar
+ 1
public class Program { public static void main(String[] args) { int min=0; int newMin = min (1,2, min); System.out.println(newMin); } public static int min( int value1, int value2 , int min){ if ( value1<value2) min=value1; else min = value2; return min; } }
1st Nov 2021, 5:10 PM
Bekzod Ganiyev
Bekzod Ganiyev - avatar
+ 1
At line 9 : You're using wrong spelling of public You've written ' pubilc ' instead of ' public '
1st Nov 2021, 6:19 PM
Sangam Sharma
Sangam Sharma - avatar
0
When i write public its give me 0 Why your code give me 1??
31st Oct 2021, 9:43 AM
STOP
STOP - avatar
0
STOP You are passing parameter as a value so you can't change that parameter value. That's would be always same as previous value. That's why you get 0 because min is 0. So if you want min value then return that min value. public static int getMin(int val1, int val2) { if (val1 < var2) { return val1; } return val2; } public static void main (String [] args) { int min = getMin(1, 10); System.out.print(min); }
31st Oct 2021, 4:54 PM
A͢J
A͢J - avatar
0
Use public not pubilc. Directly you can call the method while initializing min value. Change the return type of the method to int as it returns integer value (min). No need of taking min as argument just take the two values and assign the min value to min according to the condition and return it's value. public class Program { public static void main(String[] args) { int min=min(1,2); System.out.println(min); } public static int min(int value1, int value2){ int min; if ( value1<value2) min=value1; else min = value2; return min; } }
2nd Nov 2021, 3:17 AM
Reshma