标签:
1 js和java中的不定参数
小案列(js)
<!doctype html> <html> <head> <script> function add(){ sum=0; for( var i=0;i<arguments.length;i++){ sum=sum+arguments[i]; } return sum; } alert(add(1,3,5)); </script> </head> <body> <body> </html>
小案列(java)
public class Test{ public static void main(String[] args){ show("a","b"); show("a","b","c"); show("a","b","c","d"); show("a","b","c","d","e"); } public static void show(String...args){ for(String s: args){ System.out.print(s+" "); } System.out.println(); } }
标签:
原文地址:http://www.cnblogs.com/yaobolove/p/4679405.html