1.从键盘录入任意两个三位数,分别是最大值和最小值,再改范围内输出一个三位数,要求该三位数每一位的数字立方加起来等于这个数的本身。
package test;
public class Test {
public static void main(String[] args) {
int x = 100; int y = 500;
for(int num = x; num < y; num++) {
int a = num % 10;
int b = num /10 %10;
int c = num/100%10;
if(Math.pow(a,3) + Math.pow(b, 3)+Math.pow(c, 3) == num) {
System.out.println(num);
}
}
}
}
2.某钢厂在对成品钢卷进行排列并存放,假设钢卷编号分别为NO.3,NO.4,NO.5,NO.6,NO.7,NO.8,请用你熟悉的语法编写一个函数,打印出所有不同的组合排列,如:345678, 876543等,要求:NO.4号钢卷不能在第3位,NO.3和NO.5号钢卷不能相邻
package test;
public class Test2 {
private static String[] mustNumber = {"3","4","5","6","7","8"};
private static boolean number(String str) {
for(String num : mustNumber) {
if(str.indexOf(num) < 0) {
return false;
}
if(str.charAt(2)==4) {
return false;
}
if(str.indexOf("35") >=0 || str.indexOf("53") >= 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
int count = 0;
for(int i = 345678;i <=876543;i++) {
if(number(String.valueOf(i))) {
System.out.println(i);
count++;
}
}
System.out.println(count);
}
}