| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 636 人关注过本帖
标题:求助:进制转换
只看楼主 加入收藏
雨翔
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2007-10-4
收藏
 问题点数:0 回复次数:2 
求助:进制转换
public void actionPerformed( ActionEvent e){
    try{
    int n1 = Integer.parseInt(num1.getText());
    int n2 = Integer.parseInt(num2.getText());
    int sub[] = new int[20];  
    int index = 0;
    if(n2>1&&n2<11)
    while(n1!=0){     //如何考虑n1=0
        index++;
        sub[index] = n1%n2;
        n1/=n2;
        //这里如何利用堆栈把数组倒着输出来
    }
    else
        num3.setText(""+"请输入2至10范围的进制");
    }
    catch(Exception a){    //异常处理
        num3.setText(""+"不能输入非数值型的字符");
    }
}

谢谢各位高手~~!
搜索更多相关主题的帖子: 进制 
2007-12-21 15:38
红烧鱼
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-11-24
收藏
得分:0 
使用Integer的toString方法就可以了.
public static String toString(int i,
                              int radix)Returns a string representation of the first argument in the radix specified by the second argument.

LZ的问题使用:
           Integer.toString(n1,n2);
2007-12-21 20:03
雨翔
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2007-10-4
收藏
得分:0 
public void actionPerformed( ActionEvent e){
    try{
    int n1 = Integer.parseInt(num1.getText());
    int n2 = Integer.parseInt(num2.getText());
    //int sub[] = new int[20];  
    //int index = 0;
    if(n2>1&&n2<11)
    /**while(n1!=0){     //如何考虑n1=0
        index++;
        sub[index] = n1%n2;
        n1/=n2;
        //这里如何利用堆栈把数组倒着输出来
    }*/
        num3.setText(""+Integer.toString(n1,n2));
    else
        num3.setText(""+"请输入2至10范围的进制");
    }
    catch(Exception a){    //异常处理
        num3.setText(""+"不能输入非数值型的字符");
    }
}

呵呵~~ 高手
非常感谢~~

2007-12-22 15:03
快速回复:求助:进制转换
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011355 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved