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不能相邻)。
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不能相邻)。
第二个 既然指向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.public void fun(String str){
System.out.println(str);
}这个是对的。
Test test=new Test();
test=null;
test.fun("abc");这个明显会出现空指针的异常。
第二个会报空指针异常
2) 相当于 null.方法() 空指针异常
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());
}
}
}
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