New course! Every coder should learn Generative AI!
Try a free lesson0
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.
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;
}
+ 4
The method will be terminated if the compiler encounters any return keyword and the. It will be said as method with return value
+ 4
You may want to check out the lessons 28.1 and 29.1 of the sololearn Java course
+ 1
whereAssign assignOperator methodName Left Parenthesis parametersList rightParenthesis