/*给方法传值 * 1.形参*/ public class Geifangfachuanzhi { String name; public void bark(int x){ //x为形参 while(x>0){ System.out.println("汪"); x = x-1; //知道x为0跳出循环 } } public static void main(String[] args){ Geifangfachuanzhi dog1 = new Geifangfachuanzhi(); dog1.name = "旺财"; dog1.bark(3); // 3为实参 } }