Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:[求助!]输入问题! [Re:luyufan221]
baixiaotian





发贴: 8
积分: -1
于 2005-05-11 16:56 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.util.*;

public class TestVector {
  
  /**
   * Method main
   *
   *
   * @param args
   *
   */
   /* Vector 类与Enumeration接口
   将键盘输入的一个数字序列中
   的每位数字存储在Vector对象中,
   然后在屏幕上打印出每位数字相
   加的结果,例如:输入32打印出5 .*/
  public static void main(String[] args) {
    // TODO: Add your code here
    Vector v = new Vector();
    int b = 0;
    System.out.println("Enter your number:");
    while(true) {
      
      try{
         b = System.in.read();
      }catch(Exception e){}
      if(b=='\r'||b=='\n')
       break;
      else{
        
        int num = b - '0';
        /*
         '0' = 48;
         '1'=49;
         */
        v.addElement(new Integer(num));
      }
    }
    
    int sum = 0;
    Enumeration e = v.elements();// 基本的使用方法,使用格式
    while(e.hasMoreElements()){
    Integer intObj = (Integer)e.nextElement();
    sum+= intObj.intValue();
    } // 基本的使用方法,使用格式
    System.out.println(sum);
  }  
}




话题树型展开
人气 标题 作者 字数 发贴时间
7988 [求助!]输入问题! luyufan221 50 2005-05-11 00:46
6655 Re:[求助!]输入问题! baixiaotian 17 2005-05-11 11:33
6586 Re:[求助!]输入问题! luyufan221 13 2005-05-11 13:03
6715 Re:[求助!]输入问题! baixiaotian 906 2005-05-11 16:56
6594 Re:[求助!]输入问题! luyufan221 34 2005-05-11 22:15
6570 Re:[求助!]输入问题! luyufan221 25 2005-05-12 10:21
6427 Re:[求助!]输入问题! why 116 2005-05-15 19:49
6636 Re:[求助!]输入问题! andilyliao 23 2005-05-15 18:39
7298 Re:[求助!]输入问题! wanghang110119 180 2005-05-19 11:00

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923