1.public class Test {
public static void main(String[] args) {
private String aa="";
int  l=aa.length();
}
}
对吗?
2.public void fun(String str){
System.out.println(str);
}
public static void main(String[] args) {
Test test=new Test();
test=null;
test.fun("abc");
结果是什么?
2.编程实现矩阵显示,具体要求为输入参数打印出相应维数的矩阵(如输入4):
0000
0111
0122
0123
3.用1,2,2,3,4,5这六个数字,用java写一个main函数,打印出所有不同的排列(要求4不能出现在第三位,3、5不能相邻)。

解决方案 »

  1.   

    第一个 aa 不能定义为private 因为这里 aa 是局部变量 局部变量只能用final修饰
    第二个 既然指向NULL了那么肯定回报NullPointerException异常
    第三个
    package me.luger.base;import java.util.Scanner;
    //www.luger.me
    public class Test {
    public static void main(String[] args) {
    System.out.println("请输入维数:");
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    for (int i = 0; i < num; i++) {
    int out = 0;
    for (int j = 0; j < num; j++) {
    out = j;
    if (i < j) {
    out = i;
    }
    System.out.print(out);
    }
    System.out.println();
    }
    }}
      

  2.   

    1.此处aa为方法内的局部变量,如果用private来定义,需要放在方法外,作为成员变量
    2.public void fun(String str){
    System.out.println(str);
    }这个是对的。
    Test test=new Test();
    test=null;
    test.fun("abc");这个明显会出现空指针的异常。
      

  3.   

    第一个aa无效,在main方法中不能作为局部变量,要用final修饰
    第二个会报空指针异常
      

  4.   

    1) private String aa   private是对成员变量的修饰,不能放在方法体内
    2)  相当于 null.方法()  空指针异常
      

  5.   

    我来解答最后一题。 真爱生命,远离递归!import java.util.ArrayList;
    import java.util.List;
    public class GetOrder {
    List<String> orderResult = new ArrayList<String>();
    public static void main(String args[]){
    StringBuffer orderNumbers = new StringBuffer("122345");
    GetOrder go = new GetOrder();
    go.sortAll(new StringBuffer(""), orderNumbers);
    }
    public void sortAll(StringBuffer result,StringBuffer orderNumbers){
    for(int i=0;i<orderNumbers.length();i++){
    result.append(orderNumbers.charAt(i));
    StringBuffer tempNumbers = new StringBuffer(orderNumbers);
    tempNumbers.delete(i, i+1);
    if(result.length()<6){
    sortAll(result,tempNumbers);
    }else{
    String tempResult = result.toString();
    if(!(orderResult.contains(tempResult)||tempResult.indexOf(4)==3||tempResult.contains("35")||tempResult.contains("53"))){
    orderResult.add(tempResult);
    System.out.println(tempResult);
    }
    }
    result.delete(result.length()-1, result.length());
    }
    }
    }
      

  6.   


    4的位置判断错了if(!(orderResult.contains(tempResult)||tempResult.indexOf(4)==3||tempResult.contains("35")||tempResult.contains("53")))改为
    [code=Java]
    if(!(orderResult.contains(tempResult)||tempResult.indexOf(4)==2||tempResult.contains("35")||tempResult.contains("53")))
    [/code