zoukankan      html  css  js  c++  java
  • 方法参数

     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
  • 相关阅读:
    Java实现web页面内容抓取
    Java写入文件的几种方法及性能对比
    Java实现导出excel
    win10系统安装VMware虚拟机软件以及linux系统
    oracle11g安装教程
    oracle怎么建立本地连接
    工厂模式
    计算一个字符串中每个字符出现的次数
    MySql多表查询
    如何查看MySql的sql语句性能
  • 原文地址:https://www.cnblogs.com/linst/p/4966638.html
Copyright © 2011-2022 走看看