+ 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

27th Apr 2020, 4:15 PM
Ifeanyichukwu Faith Udoka
Ifeanyichukwu Faith Udoka - avatar
8 Réponses
+ 4
Mursalatul Pallob question is about oop in Java not in python and both are quite different!
27th Apr 2020, 4:23 PM
Abhay
Abhay - avatar
+ 3
If you want to use function again and again. Then, avoid using static.
27th Apr 2020, 4:23 PM
Tarun Kumar
Tarun Kumar - avatar
+ 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.
27th Apr 2020, 4:31 PM
Damyian G
Damyian G - avatar
0
Try this in python ...you will find more easy
27th Apr 2020, 4:20 PM
Md. Mursalatul Islam Pallob
Md. Mursalatul Islam Pallob - avatar
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 } }
27th Apr 2020, 4:25 PM
Jayakrishna 🇮🇳
0
Mursalatui ....when I'm done with java
27th Apr 2020, 4:25 PM
Ifeanyichukwu Faith Udoka
Ifeanyichukwu Faith Udoka - avatar
0
Yes it is
27th Apr 2020, 4:36 PM
Ifeanyichukwu Faith Udoka
Ifeanyichukwu Faith Udoka - avatar