public class Function {
     static String a1_1[] = {"a","b","c","d"};
     static String a2_2[] = {"a","b","c","d"};     public void tell( int i, int j ) {
           System.out.println( ("a"+i+"_"+j)[0] );
     }
     public static void main(String[] args) {          new Function().tell(1, 1);
     }}为什么怎样取数组的元素有错误,有什么别的方法可以实现吗?

解决方案 »

  1.   


    public class Function {
    static String a1_1[] = { "a ", "b ", "c ", "d " };
    static String a2_2[] = { "a ", "b ", "c ", "d " }; public void tell(int i, int j) {
    if(i == 1 && j == 1) {
    System.out.println(a1_1[0]);
    }
    if(i == 2 && j == 2) {
    System.out.println(a2_2[3]);
    }
    } public static void main(String[] args) { new Function().tell(2, 2);
    }}看着楼主的代码很奇怪啊!
      

  2.   

    这方法写的,编译也过不了啊。"a "+i+ "_ "+j这样的永远是字符串,变量名不能动态这样拼接