java吧 关注:1,256,015贴子:12,745,907

回复:【入驻JAVA吧 记录学习点滴】

只看楼主收藏回复




80楼2011-12-11 20:33
回复
    else return (fun1(a, pow--, 10) + sum(a, pow)); 才对,手误,呵呵


    81楼2011-12-11 20:43
    回复
      【程序11】
      题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
      1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列
      哈哈 一做起来就没完没了了还~~~~~ 不过这些题都很经典 进入状态了 就多做几题吧


      82楼2011-12-11 20:56
      回复

        public class Test11 {
        /**
        * 【程序11】
        *题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
        *1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。
        *
        * 额 还想达到输出格式为每行6个数字的效果~~~可以将百位是1的几个数字放一行
        * 百位是2的做下一行·········
        * */
        public static void main(String[] args) {
        int a = 0;
        int b = 0;
        int c = 0;
        int count = 0;
        for(a = 1; a <=4; a++){
        for(b = 1; b <= 4; b++){
        for(c = 1; c <= 4; c++){
        if(a != b && a != c && b != c){
        System.out.print(a + "" + b + "" + c + " ");
        count++;
        }
        }
        }
        System.out.println();
        }
        System.out.println("能组成" + count + "个互不相同且无重复的数字");
        }
        }


        83楼2011-12-11 20:56
        回复
          呵呵,楼主,写代码要注意复用的原则,给你用4个数别想当然就只是1234。


          84楼2011-12-11 21:05
          回复
            【程序12】
            题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万
            元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部
            分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可
            提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?


            85楼2011-12-11 21:17
            回复
              这个题就不做了 哈哈 没多大意思哈


              86楼2011-12-11 21:18
              回复
                哈哈~~~~~~~ 题目是说只有1 2 3 4 这四个数字么~~~唉 多谢提醒咯


                87楼2011-12-11 21:19
                回复
                  哈哈 受益了


                  88楼2011-12-12 13:20
                  回复
                    一口气做到17题~~~~~~~ 看书遇到看不懂的 郁闷
                    先上传做好的这几道题吧 写好注释先


                    89楼2011-12-12 20:33
                    回复

                      public class Test13 {
                      /**
                      * 【程序13】 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
                      * 1.程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后的结果满足 如下条件,即是结果。请看具体分析:
                      *
                      * 蛋疼的题 说好的分析呢~~~~~~~~~~
                      * */
                      public static void main(String[] args) {
                      int number = 1;
                      for(number = 1; number < 1000000; number++){
                      boolean a = WanQuanPFS.getWanQuanPFS(number + 100);
                      boolean b = WanQuanPFS.getWanQuanPFS(number + 268);
                      //如果传入的两个参数都是属于arr[]数组; 也就是说number+100 和 number+268都是完全平方数 那就打印次数number
                      if(a == true && b == true){
                      System.out.println(number);
                      }
                      }
                      System.out.println(Math.sqrt(529));
                      }
                      }
                      // 定义一个类 里面包含一个数组,数组里面存储的都是完全平方数
                      class WanQuanPFS {
                      static int[] arr = new int[1000];
                      public static boolean getWanQuanPFS(int number) {
                      for (int i = 1; i <= 1000; i++) {
                      arr[i - 1] = i * i;
                      //如果number等于数组里面某个元素就返回true;
                      if(number == arr[i - 1]){
                      return true;
                      }
                      else{
                      continue;
                      }
                      }
                      //如果数组里面所有的元素都不和参数number相等,就返回false
                      return false;
                      }
                      }


                      90楼2011-12-12 20:33
                      回复
                        import java.util.Scanner;
                        public class Test14 {
                        /**
                        * 【程序14】 题目:输入某年某月某日,判断这一天是这一年的第几天?
                        * 1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且 输入月份大于3时需考虑多加一天。
                        *
                        * 这题目真蛋疼 一看就要考虑12中不同的情况~~~我开始怎么没想到switch语句~~2B似的写的很麻烦~~~不知道有没有更简单的方法
                        *
                        * */
                        public static void main(String[] args) {
                        Scanner input = new Scanner(System.in);
                        System.out.println("请输入年份:");
                        int year = input.nextInt();
                        System.out.println("请输入月份:");
                        int month = input.nextInt();
                        System.out.println("请输入日期:");
                        int day = input.nextInt();
                        int result = 0;
                        int february = 28;
                        //判断是不是闰年,如果是就执行代码块 february = 29;
                        if (year % 400 == 0 || (year % 4 == 0 && year % 100 == 0)) {
                        {
                        february = 29;
                        }
                        }
                        switch (month) {
                        case 1:
                        result = day;
                        break;
                        case 2:
                        result = 31 + day;
                        break;
                        case 3:
                        result = 31 + february + day;
                        break;
                        case 4:
                        result = 31 + february + 31 + day;
                        break;
                        case 5:
                        result = 31 + february + 31 + 30 + day;
                        break;
                        case 6:
                        result = 31 + february + 31 + 30 + 31 + day;
                        break;
                        case 7:
                        result = 31 + february + 31 + 30 + 31 + 30 + day;
                        break;
                        case 8:
                        result = 31 + february + 31 + 30 + 31 + 30 + 31 + day;
                        break;
                        case 9:
                        result = 31 + february + 31 + 30 + 31 + 30 + 31 + 31 + day;
                        break;
                        case 10:
                        result = 31 + february + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
                        break;
                        case 11:
                        result = 31 + february + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31
                        + day;
                        break;
                        case 12:
                        result = 31 + february + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
                        + day;
                        break;
                        }
                        System.out.println(year + "年" + month + "月" + day + "号是这一年第" + result
                        + "天");
                        }
                        }
                        


                        91楼2011-12-12 20:35
                        回复
                          import java.util.Scanner;
                          public class Test15 {
                          /**
                          *
                          * 题目:输入三个整数x,y,z,请把这三个数由小到大输出。
                          * 1.程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x
                          * 与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小
                          *
                          * 这个题目就不用多讲了~~
                          * */
                          public static void main(String[] args) {
                          Scanner input = new Scanner(System.in);
                          int[] arr = new int[3];
                          for (int i = 0; i < arr.length; i++) {
                          System.out.println("请输入第" + (i + 1) + "个数字");
                          arr[i] = input.nextInt();
                          }
                          for (int i = 0; i < arr.length - 1; i++) {
                          for (int j = 0; j < arr.length - 1 - i; j++) {
                          if (arr[j] > arr[j + 1]) {
                          int temp = 0;
                          temp = arr[j];
                          arr[j] = arr[j + 1];
                          arr[j + 1] = temp;
                          }
                          }
                          }
                          for (int i = 0; i < arr.length; i++) {
                          System.out.print(arr[i] + " ");
                          }
                          }
                          }
                          


                          92楼2011-12-12 20:36
                          回复
                            public class Test16 {
                            /**
                            * 题目:输出9*9口诀。
                            *
                            * */
                            public static void main(String[] args) {
                            //i为行,j为列
                            int i = 1;
                            int j = 1;
                            for(i = 1; i <= 9; i++){
                            for(j = 1; j <= i; j++){
                            System.out.print(i+"X"+j+"="+(i*j)+"\t");
                            }
                            System.out.println();
                            }
                            }
                            }
                            这个也不用多说~~~~~ 记住两重for循环~~外层控制行,内层控制列


                            93楼2011-12-12 20:37
                            回复

                              public class Test17 {
                              /**
                              *
                              * 【程序17】 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩
                              * 下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下 的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
                              * 1.程序分析:采取逆向思维的方法,从后往前推断。
                              * 主要是要采用逆向思维推断前一天所剩下的桃子,首先知道第9天吃完后剩下一个,由次推断第8天剩下的桃子~~
                              * 推断如下:
                              * 假如第9天没有多吃一个(那第10天就剩下2个桃子),也就是正好吃上次剩下的一半:x个,那么所剩下的桃子就是2个,而这2个是第9天没吃之前的
                              * 一半 也就是说第9天本来有4个
                              *
                              * 觉得主要还是要想通啊~~~
                              *
                              * */
                              public static void main(String[] args) {
                              int taozi = 1;
                              int day = 9;
                              for (day = 9; day >= 1; day--) {
                              taozi = (taozi + 1) * 2;
                              }
                              System.out.println("第一天共摘了" + taozi + "个桃子");
                              // int t = 1534;
                              // for(int i = 1; i < 10; i++){
                              // t = ((t/2) - 1);
                              //
                              // }
                              // System.out.println(t);
                              }
                              }


                              94楼2011-12-12 21:08
                              回复