Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CodeAcademy_7_Two_DimensionalArrays_Functions;
- import java.util.Arrays;
- public class AverageFunction
- {
- public static void main(String[] args)
- {
- double result = average(10,8, 20, 10);
- System.out.println("The average is = " + result);
- int x = 10;
- int y = 9;
- swap(x,y);
- System.out.println(x);
- System.out.println(y);
- String name = "Homer";
- changeName(name);
- System.out.println("name = " + name);
- System.out.println();
- name = changeName(name);
- System.out.println("name = " + name);
- }
- public static String changeName(String name){
- return "Simpson";
- }
- public static void swap(int x, int y){
- int temp = x;
- x = y;
- System.out.println("x = " + x);
- y = temp;
- System.out.println("y = " + y);
- }
- public static double average(double first, double... values){
- double sum = Arrays.stream(values).sum();
- return sum / values.length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement