• 方法参数


     1 public class ParamTest {
     2 
     3     /**
     4      * @param args
     5      */
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8 
     9         System.out.println("Testing tripleValue:");
    10         double percent = 10;
    11         System.out.println("Before:percent:"+percent);
    12         tripleValue(percent);
    13         System.out.println("After:percent="+percent);
    14         
    15         
    16         System.out.println("
    Testing tripSalary");
    17         Employee harry = new Employee("Harry",50000);
    18         System.out.println("Before: salary=" + harry.getSalary());
    19         tripleSalary(harry);
    20         System.out.println("After: salary=" + harry.getSalary());
    21         
    22         System.out.println("
    Testing swap:");
    23         Employee a = new Employee("Alice", 70000);
    24         Employee b = new Employee("Bob", 60000);
    25         System.out.println("Before: a="+ a.getName());
    26         System.out.println("Before: b="+ b.getName());
    27         swap(a,b);
    28         System.out.println("After: a="+ a.getName());
    29         System.out.println("After: b="+ b.getName());
    30     }
    31         public static void tripleValue(double x) {
    32             x = 3*x;
    33             System.out.println("End of method: x="+x);            
    34         }
    35         
    36         public static void tripleSalary(Employee x) {
    37             x.raiseSalary(200);
    38             System.out.println("End of method: salary =" + x.getSalary());
    39         }
    40         
    41         public static void swap(Employee x, Employee y) {
    42             Employee temp = x;
    43             x = y;
    44             y = temp;
    45             System.out.println("End of method: x=" + x.getName());
    46             System.out.println("End of method: y=" + y.getName());
    47         }
    48     }
    49     
    50     
    51     
    52     class Employee {
    53         private String name;
    54         private double salary;
    55         
    56         public Employee(String n, double s) {
    57             name = n;
    58             salary = s;
    59         }
    60         
    61         public String getName() {
    62             return name;
    63         }
    64         
    65         public double getSalary() {
    66             return salary;
    67         }
    68         
    69         public void raiseSalary(double byPercent) {
    70             double raise = salary * byPercent / 100;
    71             salary += raise;
    72         }
    73     
    74 
    75 }
    View Code
  • 相关阅读:
    解决Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile
    eclipse下解决明明有jar包,却找不到的问题
    Ngnix负载均衡安装及配置
    Redis入门教程(二)
    js监听组合按键
    js清空数组的方法
    js判断浏览器是否支持webGL
    Maven入门教程(一)
    杂记
    第一天 Requests库入门
  • 原文地址:https://www.cnblogs.com/linst/p/4966638.html
Copyright © 2020-2023  润新知