java用for语句求a以内的java输出水仙花数数

10:49 提问
java我写的这个求水仙花数为什么算不出来
import java.util.S
public class Task1{
public static void main(String[] args)
Scanner input = new Scanner(System.in);
System.out.print("请输入一个数");
int number = input.nextInt();
double s=0;
int[] a={0};
for(i=0;number==0;i++)
a[i]=number%10;
number=number/10;
s=s+Math.pow(a[i],3);
if(number==(int)s)
System.out.println(number+"是水仙花数");
System.out.println(number+"不是水仙花数");
按赞数排序
Scanner input = new Scanner(System.in);
System.out.print("请输入一个数");
int number = input.nextInt();
int number1 =
double s=0;
//i改变是会数组越界的,这里也用不上数组
for(i=0;number&0;i++)//原来输入的number不等于0,为false,是不进for循环的
a=number%10;
number=number/10;
s=s+Math.pow(a,3);
if(number1==(int)s)//原来的number是会变的,比较是不对的,改成number1
System.out.println(number1+"是水仙花数");
System.out.println(number+"不是水仙花数");
int x=100,i,a,b,c;
for(;x&=999;x++)
a=x%10;b=((x-a)%100)/10;c=(x-b*10-a)/100;/*a为个位,b为十位,c为百位*/
if(x==(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)))
System.out.print(x+"\t");
因为那个number被你改成了0呀,你在对number操作的时候,将number的值改变了。所以最后跟s比较时,当然不相等算不出来呀。
import java.util.S
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.close();
Double result = 0d;
while(tmp&0){
result += Math.pow(tmp%10, 3);
if(result.intValue()==num){
System.out.println("YES");
System.out.println("NO");
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐Java小程序之水仙花数_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Java小程序之水仙花数
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
你可能喜欢水仙花数 java 程序_百度知道
水仙花数 java 程序
我有更好的答案
public class HH { /** * @param args * 1000以内的水仙花数 */
public void shuiXian(){
int n = 1000;
int y1,y2,y3;
for(int i=1;i&n;i++){
y2=i%100/10;
if((y1*y1*y1+y2*y2*y2+y3*y3*y3)==i){
System.out.println(i+&
public static void main(String[] args) {
HH a = new HH();
a.shuiXian();}}
采纳率:90%
来自团队:
* @param args
* 1000以内的水仙花数
for(int i=1;i&
public void shuiXian(){
int n = 1000;i++){
y2=i%100/10;
if((y1*y1*y1+y2*y2*y2+y3*y3*y3)==i){
System.out.println(i+&
public static void main(String[] args) {
HH a = new HH();
int y1,y2;npublic class HH { &#47
本回答被网友采纳
i&1000;).  i
a1=m&#47.isSxh(i))  System:&);
else  return false.println(&
if(m&3)\t&quot.print(i+&quot. public class shuixianhuashu {  static Boolean isSxh(int m){
int a1;10;
a3=m%10;100.
shuixianhuashu s = new shuixianhuashu();
for(int i=101;i++)
if(s;  }  public static void main(String[] args){
S1000以内的水仙花数;  else if( (a1*a1*a1+a2*a2*a2+a3*a3*a3) == (a1*100+a2*10+a3) )  return true,a2,a3  打印出所有的&水仙花数&的程序:  package shuixianhuashu
首先得在d盘下建一个叫shuixianhua.txt,否则会抛出异常import java.io.FileOutputSimport java.io.IOE// Java 中实现的代码public class shuixianhua { static Boolean isSxh(int n) {
b = n / 100;
s = n % 100 / 10;
g = n % 10;
if (n & 3)
else if ((g * g * g + s * s * s + b * b * b) == (100 * b + 10 * s + g))
else } public static void main(String[] args) throws IOException {
//1000以内的水仙花数
FileOutputStream out = new FileOutputStream(&d:\\shuixianhua.txt&);
StringBuilder sb = new StringBuilder();
for (int i = 1; i & 1000; i++){
if (shuixianhua.isSxh(i)) {
sb.append(i+&\n&);
out.write(sb.toString().getBytes()); }}
int n = 1000;
int y1,y2,y3;
for(int i=1;i&1000;i++){
y2=i/10%10;
if((y1*y1*y1+y2*y2*y2+y3*y3*y3)==i){
System.out.println(i);
public class Daffodil { public static void main(String[] args){
Daffodil d = new Daffodil();
d.perform(); }
public void perform(){
for(int i = 100; i & 999; i ++){
int b = i/100;
int s = i%100/10;
int g = i%10;
if(b*b*b+s*s*s+g*g*g==i){
System.out.println(i);
首先得在d盘下建一个叫shuixianhua.txt,否则会抛出异常 import java.io.{ //1000以内的水仙花数 FileOutputStream out = new FileOutputStream(
其他5条回答
为您推荐:
其他类似问题
您可能关注的内容
水仙花数的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Java小程序之水仙花数_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Java小程序之水仙花数
&&经典而简单的Java小程序,寻找水仙花数。
阅读已结束,下载本文需要
想免费下载更多文档?
定制HR最喜欢的简历
你可能喜欢用java语言打印出所有的水仙花数_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
用java语言打印出所有的水仙花数
你可能喜欢}

我要回帖

更多关于 java判断水仙花数 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信