美文网首页
360 面试题(预测)

360 面试题(预测)

作者: Andy_0801 | 来源:发表于2017-03-18 11:02 被阅读0次

输入M,N,输出M-N之间的所有水仙花数,如没有,输出no

package LT;

import java.util.Scanner;

/**

*

* @author 李廷

* @ClassName: Main_001

* @Version 1.5

* @Copyright JLJU

* @date 2017年3月17日 下午10:01:33

* @description 类描述

*/

public class Main_001 {

public static boolean isShui(int n) {

int g, s, b;

g = n % 10;

s = n / 10 % 10;

b = n / 100;

if ((Math.pow(g, 3) + Math.pow(s, 3) + Math.pow(b, 3)) == n) {

return true;

} else {

return false;

}

}

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int m = scanner.nextInt();

int n = scanner.nextInt();

boolean a = false;

int count = 0;

for (int i = m; i <= n; i++) {

a = isShui(i);

if (a == true) {

System.out.print(i + " ");

count++;

}

}

if (count == 0) {

System.out.println("no");

}

}

}

相关文章

网友评论

      本文标题:360 面试题(预测)

      本文链接:https://www.haomeiwen.com/subject/kbjunttx.html