杨辉三角java代码输出所有水仙花数

import java.util.*;
/*所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身*/
public class DaffodilNumber {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);// 接收控制台输入信息
System.out.print("请输入一个整数:");
int num = scan.nextInt();// 取出控制台输入的信息
if (isDaffodilNumber(num)) {// 调用isDaffodilNumber()方法
System.out.println(num + "是水仙花数!");// 若为true,输出是水仙花数
System.out.println(num + "不是水仙花数!");// 否则,输出不是水仙花数
} catch (Exception e) {
System.out.println("必须输入整数");// 捕捉异常,输入的必须为整数,若否,输出必须输入整数
// 用于判断一个整数是否是水仙花数
public static boolean isDaffodilNumber(int i) {
boolean flag =
int a = i / 100; // 取得百位数
int b = (i / 10) % 10; // 取得十位数
int c = i % 10; // 取得个位数
if ((Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3)) != i) {// 若各位数字立方和不等于该数本身
flag =// 返回false
浏览: 4867 次
来自: 徐州
Chris_bing 写道36行的
for (int i = ...
36行的 for (int i = 2; i &= Ma ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'2011年10月 Java大版内专家分月排行榜第三
2015年7月 Web 开发大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。java打印输出所有的水仙花数..拜托了各位,我没分了_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
java打印输出所有的水仙花数..拜托了各位,我没分了
我有更好的答案
outpublic static void main(String[] args) {
int temp=0; 10;
if (i == x * x * x + y * y * y + z * z * z) {
System.print(i+&
int y = temp % 10;);
for (int i = 100; i & 10;
int z = temp /\t& 999; i++) {
int x = temp % 10;
temp = temp &#47
采纳率:42%
来自团队:
为您推荐:
其他类似问题
您可能关注的内容
水仙花数的相关知识
换一换
回答问题,赢新手礼包

我要回帖

更多关于 杨辉三角java代码 的文章

 

随机推荐