【java数据结构和算法】给定一个数n,将其扩大为原来的15倍,不能使用乘法、除法和加法,这个怎么写呢,谢谢?
天蓬老师
天蓬老师 2017-04-18 09:44:50
0
2
367

【java数据结构和算法】给定一个数n,将其扩大为原来的15倍,不能使用乘法、除法和加法,这个怎么写呢,谢谢?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
刘奇

Hmm, I was confused just now.
Shift left by 4 bits and subtract n. Without considering overflow.
16=2^4

(n<<4)-n
大家讲道理
public class Test {

    public static void main(String[] args) {
        System.out.println(expand15Times(100));
    }

    private static int expand15Times(int n) {
        return (n << 4) - n;
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!