public static void main(String[] args) 
要把主函数中参数args赋给一个字符数组 
该怎么赋值?谢谢

解决方案 »

  1.   

    http://100.tongbuedu.com/netschool/BBS/ShowPost.asp?ThreadID=1009
      

  2.   

    可以选择输入的字符串中的每个字符以一个符号隔开 例如 h-e-l-l-o- -w-o-r-l-d
    在使用 split("-")
      

  3.   

    方法很多,我也来写一种,应该效率还行。
    public class Foo {
        
    public static void main(String[] args){
        
        int maxDimension=0 ; //用它来记录最后转换出来的字符数组的维数 
        
        for (int i=0 ; i<args.length ; i++ ){
            maxDimension+=args[i].length() ;       //计算维数       
        }    char[] result = new char[maxDimension] ;   //记录最后的转换结果
       
        int record = 0;    //用来在下面复制数组时记录已复制维数   
        
        for (int i=0 ; i<args.length ; i++ ){
            //System.arraycopy方法是个原生的方法在复制数组时速度很快。
            System.arraycopy(args[i].toCharArray(),0,result,record,args[i].length()) ;
            record+=args[i].length() ;   
        }      System.out.println(result) ;}
      

  4.   

    不行啊 ,运行的时候出错
    Exception in thread "main" java.lang.NullPointerException
            at strcode.main(strcode.java:58)
      

  5.   

    api啊api
    char[]  toCharArray()
              Converts this string to a new character array.
      

  6.   

    回复人:rsnowy() ( ) 信誉:100
    不行啊 ,运行的时候出错
    Exception in thread "main" java.lang.NullPointerException
    at strcode.main(strcode.java:58)不是吧?我这就可以运行阿你加参数没?
      

  7.   

    。大哥 ,Exception in thread "main" java.lang.NullPointerException
    at strcode.main(strcode.java:58)   strcode.java是你的文件吧?
    你把我的代码单独保存为Foo.java运行看看