+ 1
I tried running this code by writing the static int method first before the main method and it didn't work
static int max(int a, int b) { if(a > b) { return a; } else { return b; } public static void main(String[ ] args) { int res = max(7, 42); System.out.println(res); //42 } } But the first explaination on return type was done like mine
8 Réponses
+ 4
Mursalatul Pallob question is about oop in Java not in python and both are quite different!
+ 3
If you want to use function again and again. Then, avoid using static.
+ 1
Is this code contained inside a class? The only other issue I can see is that you have a brace mismatch in the max() method, it's missing an ending curly brace.
0
Try this in python ...you will find more easy
0
It's works.. Try again
But your question is not clear to me..
So can you elaborate it more pls..?
Edit:
Ifeanyichukwu Faith Udoka this works
public class Program
{
static int max(int a, int b) {
if(a > b) {
return a;
}
else {
return b;
}
}
public static void main(String[ ] args) {
int res = max(7, 42);
System.out.println(res); //42
}
}
0
Mursalatui ....when I'm done with java
0
Yes it is