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

📄 ex4.java

📁 讲述各种各样的java初始编程 了解编程
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package chenchao1;import java.util.*;/** * * @author williechen */public class Ex4 {    ArrayList<Integer> result = new ArrayList<Integer>();    public static void main(String[] args) {        Ex4 ex4 = new Ex4();        ex4.getNarcissus();        System.out.println(ex4.result);    }    void getNarcissus() {        for (int i = 100; i <= 999; i++) {            String temp = Integer.toString(i);            char[] ia = temp.toCharArray();            int sum = 0;            int product = 0;            for (char c : ia) {                int t = c - 48;         // here, the ASCII code's number starts from 48                product = (int)Math.pow(t, 3);                sum += product;            }            if (sum == i) {                result.add(i);            }        }    }}

⌨️ 快捷键说明

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