2.分析以下需求,并用代码实现:
(1)定义如下方法public static String getPropertyGetMethodName(String property);
(2)该方法的参数为String类型,表示用户给定的成员变量的名字,返回值类型为String类型,返回值为成员变量对应的get方法的名字
(3)如:用户调用此方法时给定的参数为"name",该方法的返回值为"getName"
1 public class Test_002 { 2 3 public static void main(String[] args) { 4 System.out.println(getPropertyGetMethodName("age")); 5 } 6 public static String getPropertyGetMethodName(String property){ 7 return "get"+property.substring(0, 1).toUpperCase()+property.substring(1); 8 } 9 }
运行结果:
1 getAge