java 水仙花

来源:互联网 发布:ovid数据库优点 编辑:程序博客网 时间:2024/05/17 03:58
package first;
import java.util.Scanner;
public class First {


public static void main(String[] args) {

// TODO Auto-generated method stub
num();
getshuixianhuashu();

}


static void num()
{
int num;
for(int i=100;i<1000;i++)
{
num=i;
 
if(Math.pow((num%10),3)+Math.pow((num/100),3)+Math.pow((num/10%10),3)==i)
{
System.out.println(i);
}
}
 
 
}
static void getshuixianhuashu()
{
int a,b,c,n;
Scanner s1=new Scanner(System.in);
    n=s1.nextInt();
for(int i=100;i<=n;i++)
{
String s=i+"";
char[] str=s.toCharArray();
a=str[0]-48;
b=str[1]-48;
c=str[2]-48;
if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==i)
{
System.out.println(i);
}
}
 
 
}
}
原创粉丝点击