关于JAVA字符串对象数组的循环次数问题

来源:互联网 发布:android开源项目源码 编辑:程序博客网 时间:2024/05/16 15:12

代码如下,为什么

static class Bomblet extends Telephone{  //小灵通类
  
  String[] record;  //通讯录记录  
  double receivedTime; //被叫时间
  
  Bomblet(String b, String n){
   super(b, n);
  }
     double getReceivedTime( ) { return receivedTime; }  
     void setReceivedTime(double d) {
      receivedTime = d;  //设置被叫时间   
     }
    
     void builtNumberBook(){  //建立简单通讯录 
      int sum;
//      String s = "";
      Scanner read = new Scanner(System.in);
      System.out.print("请输入您要建立的通讯录记录条数:");
      sum = read.nextInt();
      record = new String[sum];
      System.out.print("请输入您要建立的"+sum+"条通讯录记录");
      System.out.println("(请以“姓名+空格+号码”的格式输入,每条记录以回车结束):");

**********************************************************

//为什么sum = 3 时,只循环2次
      for(int i = 0; i < record.length; i++){
       record[i] = read.nextLine();      
      }

**************************************************************
      System.out.print(record.length);
      System.out.print("您已成功建立"+sum+"条通讯录记录,你可以调用相应函数查询通讯录!");      
     }

结果图:

 

原创粉丝点击