java 面试题2

   1.二维数组

   2.单个对象实现链表

  public class User {
 
 private String userName;
 static User user;
 private User next;
 
 public User(String userName){
  this.userName=userName;
  next = user;
  user=this;
 }

 
 public static void main(String args[]){
  
  User u1 = new User("a");
  User u2 = new User("b");
  User u3 = new User("c");
  
  do{
   System.out.println(User.user);
  }while((user=user.next) !=null);
  
 }
 
 public String toString(){
  return this.userName;
 }
}

//二维数组
  int[][] a={{1,1,1},{2,2},{3,3}};
  int sum=0;
  System.out.println(a.length);   //a的长度
  for(int i=0;i<a.length;i++){
   for(int j=0;j<a[i].length;j++){  //二给数组里面的一维数组的长度
    System.out.println("i="+i+" , j="+j);
    sum+=a[i][j];
   }
  }
  System.out.println(sum);

猜你喜欢

转载自zw7534313.iteye.com/blog/2225054