⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sxh.java

📁 在java中实现水仙花数的各算法
💻 JAVA
字号:
import java.io.*;
public class SXH{
	void function(int n){
		for(double i=Math.pow(10,n-1);i<Math.pow(10,n);i++){
			int j=(int)Math.pow(10,n);
			int x=0;
			double total=0;
			while(j>=10){
				x=(int)(i%j)/(j/10);
				total=total+Math.pow(x,n);
				j=j/10;
				}
			if(total==i)System.out.println(total);	
			}	
		}
	public static void main(String arg[]){
		System.out.println("请输入n(n>=3):");
		int h=0;
		try{BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
		    String InputLine=in.readLine();
		    h=Integer.valueOf(InputLine).intValue();
		}catch(Exception e){}
		SXH a=new SXH();
		if(h>=3)a.function(h);
		else System.out.println("输入错误");
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -