/**
* 好像是叫回数问题还是什么,就是一个整数正序和反序都是一个数,如:121,222,12321
* @author 00
*
*/
public class RollNumber {
boolean isRollNumber(int number) {
String numberStr = Integer.toString(number);
char[] numberChar = numberStr.toCharArray();
int length = numberChar.length;
for (int i = 0; i < length/2; i++) {
if (numberChar[i] != numberChar[length-i-1]) {
return false;
}
}
return true;
}
public static void main(String[] args) {
System.out.println(new RollNumber().isRollNumber(6776));
}
}
/**
* 获取一个四位随机数,并且四位数不能重复
* @author 00
*
*/
public class RandomNumber {
public static void main(String[] args) {
Set<Integer> randomSet = new HashSet<Integer>();
Random random = new Random();
while (randomSet.size() < 4) {
int tmp = random.nextInt(10);
randomSet.add(tmp);
}
System.out.println(randomSet);
Object[] randomArray = randomSet.toArray();
int result = ((int)randomArray[0] * 1000) +
((int)randomArray[1] * 100) +
((int)randomArray[2] * 10) +
(int)randomArray[3];
System.out.println(result);
}
}