0
Error fast help
What is error https://code.sololearn.com/cXz7FJ64ybMB/?ref=app
9 ответов
+ 3
public not a pubilc
+ 1
But the code doesn't work correctly
+ 1
What do you need according to the program? Count the smallest of the two numbers? Why min is equal to 0?
+ 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;
}
}
+ 1
At line 9 :
You're using wrong spelling of public
You've written ' pubilc ' instead of ' public '
0
When i write public its give me 0
Why your code give me 1??
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);
}
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;
}
}