A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© iori   /  2016-1-14 20:42  /  5213 人查看  /  76 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

class Test {
        public static void main(String[] args) {
//有1,2,3,4  个数字,问能组成多少个互不相同且无重复数字的三位数。,都是多少
                String[] str1 = {"1","2","3","4"};
                String[] str2 = str1;
                String[] str3 = str1;
                int count = 0;

                for(int i=0;i<str1.length;i++){
                        for(int j=0;j<str2.length;j++){
                                for(int k=0;k<str3.length;k++){
                                        if(i!=j && j != k && k != i){
                                                System.out.println(str1[i]+str2[j]+str3[k]);
                                                count++;
                                        }
                                }
                        }
               
                }
                System.out.println("总共有"+count+"个");
        }
}

评分

参与人数 1黑马币 +1 收起 理由
洋葱头头 + 1 神马都是浮云

查看全部评分

回复 使用道具 举报 3 0
public class Test1 {
        public static void main(String[] args) {
                        int count =0;
                for(int x=100;x<1000;x++){
                        int ge = x%10;
                        int shi = (x/10)%10;
                        int bai = x/100;
                        
                        if(((ge != shi) && (ge != bai)) && (shi!=bai)){
                                        if(((ge<=4 && ge > 0)&&(shi<=4 && shi > 0))&&(bai<=4 && bai > 0)){
                                                System.out.println(x);
                                                count++;
                                }
                        }
        }
                System.out.println(count);
        }
}

还是给你修改下吧
回复 使用道具 举报 1 0
三位数 是1 2 3 4 而不是 0 1 2 3 4
回复 使用道具 举报
iori 中级黑马 2016-1-16 13:42:18
24#
额,这样啊,好不容易做出一道 面试题 ,太得意了,忘了0了
回复 使用道具 举报
谢谢分享! 加油
回复 使用道具 举报
看了半天,没看懂是什么意思,能私密分享一下吗
回复 使用道具 举报
别开心的太早哦,程序有误,if(((ge<=4)&&(shi<=4))&&(bai<=4))这里应该改成if(ge<=4 && shi<=4 && bai<=4 && ge * shi * bai !=0),请看题目,审题啊。。。。。
回复 使用道具 举报
66666666666666666666666666
回复 使用道具 举报
一起思考一起学习
回复 使用道具 举报
给力~~~~~~~~~~~
回复 使用道具 举报
加油吧!
回复 使用道具 举报
学习了。
回复 使用道具 举报
厉害!!!
回复 使用道具 举报
运行了一下,怎么不对呀
回复 使用道具 举报
C语言中经常出现的水仙花数,JAVA学习中
回复 使用道具 举报
~~~~~~~~~~~~~~~~·
回复 使用道具 举报
  1. public class t {
  2.     public static void main(String[] args) {

  3.             int i,j,k,count=0;
  4.             for(i=1;i<=4;i++){
  5.                      for(j=1;j<=4;j++){
  6.                              for(k=1;k<=4;k++){
  7.                                      if(i!=j && j!=k && i!=k) {
  8.                                              System.out.print(i*100+j*10+k+" ");
  9.                                              count++;
  10.                                      }
  11.                              }
  12.                      }
  13.             }
  14.             System.out.println();
  15.             System.out.println(count+"个");
  16.     }
  17. }
复制代码

和楼主分享经验
回复 使用道具 举报
Forwhat 发表于 2016-1-15 11:42
那俩if判断语句括号是不是有点多余啊,这样写不行么(ge != shi) && (ge != bai) && (shi!=bai) ...

题目是1 2 3 4组成的数字
回复 使用道具 举报
谢谢分享,学习了
回复 使用道具 举报
zhuyapeng 发表于 2016-1-15 07:46
水仙花数  面试出现的几率挺高的

这不是水仙花数好么!水仙花数是正向思维,这个是逆向思维,有难度,如果笔试时来一道这样的题目,果断跪了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马