Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Return is Returning Blank

I'm trying to create a java method that returns the sum of two values x and y. Currently when I run the code, the output isn't returning anything. Is there any way I can get the value to return the sum WITHOUT modifying the "getSum(x,y);" in line 6 while using the return method???

public class ZawMethods2
{
  public static void main(String[] args)
  {
    int x = 7, y = 45; 
    getSum(x,y);
  }
  public static int getSum(int x, int y){
    int sum = x+y; 
    return (sum); 
  }
}

Thank you all in advance!!! I'm still in the beginning stage of coding so I appreciate all the help.

like image 596
zawl Avatar asked Sep 10 '26 20:09

zawl


1 Answers

Sorry I thought that you are not allowed to modify getSum method. Just add System.out.println(sum); to getSum method.

like image 60
zhh Avatar answered Sep 13 '26 10:09

zhh