| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 822 人关注过本帖
标题:NUM为定值是可以运行,若用循环for(NUM=1;NUM<=20;NUM++)则出错
只看楼主 加入收藏
zhongnaner
Rank: 1
等 级:新手上路
帖 子:2
专家分:1
注 册:2012-9-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
NUM为定值是可以运行,若用循环for(NUM=1;NUM<=20;NUM++)则出错
下面程序NUM为定值是可以运行,若用循环for(NUM=1;NUM<=20;NUM++)则出错
int Counter[];
        int Sum[];
        Counter=new int[40];
        Sum=new int[40];
        int Num=20;
        int Inum;
        int Jcon=39;
        int n;
        int m;
        
        for(Num=20;Num>0;Num--)
        {
            //////
            for(int i=0;i<40;i++)//初始化数组
            {
                Counter[i]=0;
            }
            
            Counter[Jcon]=Num;
            for(Inum=1;Inum<NUM;INUM++) 乘几次
            {
                for(n=0;n<40;n++)
                {
                     Counter[n]=Counter[n]*Num;
                }
                for(Jcon=39;Jcon>0;Jcon--)
                {
                     Counter[Jcon-1]=Counter[Jcon-1]+Counter[Jcon]/10;
                     Counter[Jcon]=Counter[Jcon]%100%10;                                                
                }
                    
                                            
            }
            ///////
            /*for(int s=39;s>=0;s--)
            {
                Sum[s]=Sum[s]+Counter[s];
            }
            for(Jcon=39;Jcon>=1;Jcon--)
            {
                Sum[Jcon-1]=Sum[Jcon-1]+Sum[Jcon]/10;
                Sum[Jcon]=Sum[Jcon]%10;                                                
            }*/
            for(int h=0;h<=39;h++)
            {
                System.out.print(Counter[h]);
            }
            System.out.println();
        
        }
2013-03-26 23:02
Kingbox_tang
Rank: 7Rank: 7Rank: 7
来 自:天津师范大学
等 级:黑侠
威 望:3
帖 子:146
专家分:677
注 册:2012-11-27
收藏
得分:10 
同学,你看看红的地方
package com.chinasoft.ti;

public class MU {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int Counter[];
        int Sum[];
        Counter=new int[40];
        Sum=new int[40];
        int Num=20;
        int Inum;
        int Jcon=39;
        int n;
        int m;
        
        for(Num=20;Num>0;Num--)
        {
            //////
            for(int i=0;i<40;i++)//初始化数组
            {
                Counter[i]=0;
            }
            
            Counter[Jcon]=Num;
            for(Inum=1;Inum<Num;Inum++) //乘几次
            {
                for(n=0;n<40;n++)
                {
                     Counter[n]=Counter[n]*Num;
                }
                for(Jcon=39;Jcon>0;Jcon--)
                {
                     Counter[Jcon-1]=Counter[Jcon-1]+Counter[Jcon]/10;
                     Counter[Jcon]=Counter[Jcon]%100%10;                                                
                }
                    
                                            
            }
            for(int s=39;s>=0;s--)
            {
                Sum[s]=Sum[s]+Counter[s];
            }
            for(Jcon=39;Jcon>=1;Jcon--)
            {
                Sum[Jcon-1]=Sum[Jcon-1]+Sum[Jcon]/10;
                Sum[Jcon]=Sum[Jcon]%10;                                                
            }
            for(int h=0;h<=39;h++)
            {
                System.out.print(Counter[h]);
            }
            System.out.println();
        
        }

    }

}
但是你的输出 结果是要这个吗?
0000000000000104857600000000000000000000
-306639989000000000000000000000000000000000000000
457441280000000000000000000000000000000000000000
1681328401000000000000000000000000000000000000000
0000000000000000000000000000000000000000
1500973039000000000000000000000000000000000000000
-1282129920000000000000000000000000000000000000000
-1692154371000000000000000000000000000000000000000
-251658240000000000000000000000000000000000000000
1843829075000000000000000000000000000000000000000
1410065408000000000000000000000000000000000000000
387420489000000000000000000000000000000000000000
16777216000000000000000000000000000000000000000
823543000000000000000000000000000000000000000
46656000000000000000000000000000000000000000
3125000000000000000000000000000000000000000
256000000000000000000000000000000000000000
27000000000000000000000000000000000000000
4000000000000000000000000000000000000000
1000000000000000000000000000000000000000

旨在提高编程水平,学有所用,学有所成,学有所为。
2013-03-27 09:43
丶XCC丶
Rank: 2
等 级:论坛游民
帖 子:13
专家分:50
注 册:2013-3-20
收藏
得分:10 
你的逻辑不对哟,你看,
1、外面已经定义看Num的值,在for循环中,干嘛还要声明他的值。
2、很多的for循环套在一个大的for循环中,外面的变量最大才为20,里面的for循环居然有39的。
3、初始化数组时,怎么要放在外面的for循环里面呢。

你要实现什么功能啊???
说说,我想想,明晚见。
2013-04-01 22:34
快速回复:NUM为定值是可以运行,若用循环for(NUM=1;NUM<=20;NUM++)则出错
数据加载中...
 
   



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

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