+ 1

Challenge for you: why this code doesn't run ( I don't know😉)

public class MyClass { public static void main(String[ ] args) { int x = 5; int y= square(x); System.out.println("The square of "+x+" is "+y); } static void square(int num) { num *= num; } }

27th Jul 2020, 11:21 AM
Theo Martier
Theo Martier - avatar
7 ответов
+ 5
Because you aren't returning value from function like "return num" in square function
27th Jul 2020, 11:22 AM
Abhay
Abhay - avatar
+ 5
Ok thanks all AKSHAY codemonkey Abhay
27th Jul 2020, 11:53 AM
Theo Martier
Theo Martier - avatar
+ 3
Great ! thanks Akshay, code monkey and Abhay!
27th Jul 2020, 11:33 AM
Theo Martier
Theo Martier - avatar
+ 2
Ok i will try ...
27th Jul 2020, 11:25 AM
Theo Martier
Theo Martier - avatar
+ 2
27th Jul 2020, 11:28 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 1
Theo Martier type @ then a list of suggestions will pop and select the name of person you want to tag
27th Jul 2020, 11:40 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 1
You should use return statement in your 'square' function then it will work
27th Jul 2020, 2:48 PM
Devesh
Devesh - avatar