Code Hunt Sector 04 Conditionals - Java

原创
2016/06/04 13:54
阅读数 92

微软编码游戏 https://www.codehunt.com

Code Hunt 04.01

public class Program {
    public static Boolean Puzzle(Boolean x, Boolean y) {
        return x || y;
    }
}

 

Code Hunt 04.02

public class Program {
    public static Boolean Puzzle(Boolean x, Boolean y) {
        return x && y;
    }
}

 

Code Hunt 04.03

public class Program {
    public static Boolean Puzzle(int x) {
         return x < 50;
    }
}

 

Code Hunt 04.04

public class Program {
    public static Boolean Puzzle(int x, int y) {
        return x < y;
    }
}

 

Code Hunt 04.05

public class Program {
    public static int Puzzle(int i) {
        return (i >> 31) | (-i >>> 31);
    }
}

 

Code Hunt 04.06

public class Program {
    public static Boolean Puzzle(int i, int j) {
        return false;//令人无语
    }
}

 

Code Hunt 04.07

public class Program {
    public static int Puzzle(int i) {
		return i < 100 ? 2 : 3;
    }
}

 

Code Hunt 04.08

public class Program {
    public static String Puzzle(int i) {
        return i % 2 == 0 ? "even" : "odd";
    }
}

 

Code Hunt 04.09

public class Program {
    public static String Puzzle(int i) {
        return i % 5 == 0 ? "multiple of 5" : "not a multiple of 5";
    }
}

 

Code Hunt 04.10

public class Program {
    public static String Puzzle(int i, int x) {
        return i % x == 0 ? ("multiple of " + x) : ("not a multiple of " + x);
    }
}

 

Code Hunt 04.11

public class Program {
    public static String Puzzle(int i, int j, int k) {
        return i == 2 * j && j == 2 * k ? "yes!" : "no";
    }
}

 

Code Hunt 04.12

public class Program {
    public static int Puzzle(int i) {
        return i > 14 ? 21 : (i - 1) / 7 * 7;
    }
}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部