How to call method (with a return type) in another method (with void type) in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to call method (with a return type) in another method (with void type) in java

1- SUMEVEN: Declare a method with no return value to print a message "The sum of even numbers are=" and to call the SUM method. 4- SUMODD: Declare a method with no return value to print a message "The sum of odd numbers are=" and to call the SUM method. 5- SUM: Declare a method to calculate the sum of two variables and return the result.

10th Nov 2021, 4:21 PM
Ghaida Alomari
4 Answers
+ 1
public void sumEven(int num1, int num2) { System.out.println(“The sum of even numbers are= “ + sum(num1, num2)); } public void sumOdd(int num1, int num2) { System.out.println(“The sum of odd numbers are= “ + sum(num1, num2)); } public int sum(int num1, int num2) { return num1 + num2; }
11th Nov 2021, 7:13 AM
Emiliano Rodriguez
Emiliano Rodriguez - avatar
+ 4
The method will be terminated if the compiler encounters any return keyword and the. It will be said as method with return value
10th Nov 2021, 4:32 PM
[ §andi¶ ]
[ §andi¶ ] - avatar
+ 4
You may want to check out the lessons 28.1 and 29.1 of the sololearn Java course
10th Nov 2021, 4:34 PM
Lisa
Lisa - avatar
+ 1
whereAssign assignOperator methodName Left Parenthesis parametersList rightParenthesis
11th Nov 2021, 1:03 AM
zemiak