/* 在控制台输出所有的“水仙花数” 水仙花:100-999 在以上数字范围内:这个数=个位*个位*个位+十位*十位*十位+百位*百位*百位 例如:xyz=x^3 +y^3 +z^3 怎么把三位数字拆成每位整数 思路:百位: int x= i / 100 十位: int y = i / 10 % 10 个位: int z = i % 10 */ class LoopTest3 { public static void main(String[] args) { for (int i=100; i
琐碎知识: 水仙花数, ASCII码, 冒泡排序, 简单选择排序, 折半查找 1.水仙花数 每位数的平方的和等于本身. 如100到999之间的水仙花数满足: 个位的平方+十位的平方+百位的平方 = 本身. public class Test02{ public static void main(String[] args){ int g = 0;//存储个位 int s = 0;//存储十位 int b = 0;//存储百位 for(int i=100; i<999; i++) { g = i%
package printDaffodilNumber; /* * 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.(100~1000) * 比如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方. */ public class printNumber { static int number1; static int number2; static int number3;
水仙花数是三位数,它的各位数字的立方和等于这个三位数本身,例如:371=33+73+13,371就是一个水仙花数. 要判断是否是水仙花数,首先得得到它的每一位上的数.个位数即为对10取余:十位数为对100取余减去个位数再除以10,百位数为减去对100取余后的数再除以100. 代码如下: public class shuixianhua { public static void main(String args[]){ int x=100; int a,b,c; while(x<=999){ a=
1.打擂台 简单的小代码,打擂台.纪念下过去,祝福下新人. public static void main(String[] args){ int[] ld = {1,4,2,10,8,9,5}; int max = ld[0]; for(int i = 1;i<ld.length;i++){ if(ld[i]>max){ max=ld[i]; } } System.out.print(max); } 2.冒泡排序 还是简单的小代码,冒泡排序.纪念下过去,祝福下新人. public stati
水仙花数 水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI).自恋数.自幂数.阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153). // 取个位.十位.百位.千位依次这样计算:n/1%10,n/10%10,n/100%10,n/1000%10 public class T