package cp03.se03_peopleLei; public class exp01 { // 返回类型 return 对应 int int speak(String name,int age,String ...aihaomen){ System.out.println("我叫"+name+",我今年"+age+"岁了"); System.out.print("我的爱好是:"); for(String aihao:aihaomen){ System.out.print(aihao+" "); } // 获取爱好长度 int sumaihao=aihaomen.length; return sumaihao; } public static void main(String[] args) { exp01 zhangsan=new exp01(); int n=zhangsan.speak("张三",23,"打球","游泳"); System.out.println(",有"+n+"个爱好"); } }
输出结果为
我叫张三,我今年23岁了 我的爱好是:打球 游泳 ,有2个爱好
时间: 2024-10-11 06:37:45