java方法参数
import java. util. * ;
public class Main {
public static void main ( String [ ] args)
{
var res1= new Employee ( "lol" , 100000 ) ;
var res2= new Employee ( "wzry" , 5000 ) ;
System . out. println ( "方法不能修改基本数据类型的参数!!" ) ;
double percent= 10 ;
triplevalue ( percent) ;
System . out. println ( "percent的值为" + percent) ;
System . out. println ( "方法能改变对象参数的状态!!!" ) ;
triplesalary ( res1) ;
System . out. println ( "res1 salary:" + res1. getsalary ( ) ) ;
System . out. println ( "方法不能让一个对象参数引入一个新的对象" ) ;
swap ( res1, res2) ;
System . out. println ( res1. getname ( ) + " " + res1. getsalary ( ) ) ;
System . out. println ( res2. getname ( ) + " " + res2. getsalary ( ) ) ;
}
public static void triplevalue ( double x)
{
x= 3 * x;
System . out. println ( "End of method X:" + x) ;
}
public static void triplesalary ( Employee x)
{
x. raisesalary ( 200 ) ;
System . out. println ( "End of method salary:" + x. getsalary ( ) ) ;
}
public static void swap ( Employee a, Employee b)
{
Employee temp= a;
a= b;
b= temp;
}
}
class Employee
{
private String name;
private double salary;
public Employee ( String n, double s)
{
name= n;
salary= s;
}
public String getname ( )
{
return name;
}
public double getsalary ( )
{
return salary;
}
public void raisesalary ( double bypercent)
{
double num= bypercent* salary/ 100.0 ;
salary= salary+ num;
}
}