How to use void sum

Hello, I want to use sum but I don’t know where to put number. is there anything that can help? Thank You!

void sum(int a, int b, int c) {
  in total = a + b + c;

Keyword void is intended for functions which don’t return anything.

For returning anything else we’ve gotta declare which datatype a function must return.

Here’s a sum() function example for the int primitive datatype:

static final int sum(final int... values) {
  int total = 0;
  for (final int v : values) total += v;
  return total;

Based on your post and avoiding advanced syntax you can do

// Calculate the sum of 3, 4 and 5
int total = sum(3, 4, 5);

int sum(int a, int b, int c){
  return a + b + c;

Thank you for the help!!

1 Like

thank you for the explanation!

1 Like