186k views
5 votes
add is a method that accepts two int arguments and returns their sum. Two int variables, euroSales and asiaSales, have already been declared and initialized. Another int variable, eurasiaSales, has already been declared. Write a statement that calls add to compute the sum of euroSales and asiaSales and that stores this value in eurasiaSales. Assume that add is defined in the same class that calls it.

1 Answer

4 votes

Answer:

// here is code in Java.

// package

import java.util.*;

// class definition

class Main

{

// method that return sum of two sale value

public static int Add(int euroSales,int asiaSales)

{

// return the sum

return euroSales+asiaSales;

}

//main method of the class

public static void main (String[] args) throws java.lang.Exception

{

try{

// variables

int euroSales=100;

int asiaSales=150;

int eurasiaSales;

// call the function

eurasiaSales=Add(euroSales,asiaSales);

// print the sum

System.out.println("total sale is:"+eurasiaSales);

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Declare and initialize two variables "euroSales=100" and "asiaSales=150". Declare another variable eurasiaSales. Call the method Add() with euroSales and asiaSales as parameter. This method will add both the value and return the sum.This sum will be assigned to variable eurasiaSales.Then print the sum.

Output:

total sale is:250

User Ankur Bavishi
by
8.4k points