// 10/2/2017 // return value // A method should be able to give back an answer based on its // calculations, e.g. sqrt, pow, abs, average import java.util.Scanner; /** This class illustrates returning a value from a method */ public class ReturnValues { /** main method calls two different methods * */ public static void main(String[] args) { double num1=5.1, num2=26.7; System.out.println("sum is " + calculateSum(num1, num2)); double s; s=calculateSum(95.4, num1); System.out.println("In main, value of s is: " + s); } /** * method calculateSum accepts 2 double values and adds them. * @param val first value to be added. * @param val2 second value to be added. * @return returns the sum of the 2 numbers. */ // data type of the value to return goes before name of method public static double calculateSum(double val, double val2) { // sum is called a local variable double sum=val+val2; return sum; } } /* up to here. * Show how to get rid of sum and return value of expression. * Lab next time will be on methods with return value and parameters */