📄 ex4.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 + -