public class GuessYear {
/**
* 判断两个数组中的数字是否有相同的
* @param x
* @param y
* @return
*/
boolean isEqual(long[] x,long[] y){
boolean flag = false;
int len = x.length;
int len1 = y.length;
//判断两个数组间是否有相同的数字
for(int i = 0; i < len; i++){
for(int j = 0; j < len1; j++){
if(x[i] == y[j])
flag = true;
}
}
//判断第一个数组内是否有相同的数字
for(int i = 0; i < len; i++){
long tmp = x[i];
for(int j = i+1; j < len; j++){
if(tmp == x[j])
flag = true;
}
}
//判断第二个数组内是否有相同的数字
for(int i = 0; i < len1; i++){
long tmp = y[i];
for(int j = i+1; j < len1; j++){
if(tmp == y[j])
flag = true;
}
}
return flag;
}
/**
* 判断某数字是几位数
* @param tmp
* @return
*/
boolean isWhatBit(long num,int bit){
int count = 0;
while(num != 0){
num /= 10;
count++;
}
if( count == bit) return true;
else return false;
}
/**
* 将数字分离到数组中
* @param a
* @param x
*/
void splitNumber(long num,long []x){
int i = x.length - 1;
while(num != 0){
x[i--] = num % 10;
num /= 10;
}
}
/**
* 猜年龄
*/
void guess(){
long x[] = new long[4];
long y[] = new long[6];
long row,col;
row = col = 10;
for(long i = 1; i < row; i++){
for(long j = 0; j < col; j++){
long tmp = i*10+j;
long f = tmp*tmp*tmp;
long s = f*tmp;
if(!isWhatBit(f,4))
continue;
if(!isWhatBit(s,6))
continue;
splitNumber(f,x);
splitNumber(s,y);
if(!isEqual(x,y))
System.out.println(tmp);
}
}
}
}
请你提交:能组成的4位素数的个数,不要罗列这些素数!!
public class FourWeiPrime {
boolean isPrime(int n){
boolean flag = true;
for(int i = 2; i*i <= n; i++){
if(n % i == 0)
flag = false;
}
return flag;
}
boolean isInclude1949(int n){
boolean flag = false;
int y[] = {0,0,0,0};
int count = 0;
while(n != 0){
int r = n%10;
if(r == 1){
y[0] = 1;
}else if(r == 4){
y[1] = 1;
}else if(r == 9){
if(y[2] != 1){
y[2] = 1;
}else if(y[3] != 1){
y[3] = 1;
}
}
n /= 10;
}
for(int i = 0; i < 4; i++){
if(y[i] == 1){
count++;
}
}
if(count == 4){
flag = true;
}
return flag;
}
void prime(){
int init = 1000;
int max = 9999;
int ln = 0;
int count = 0;
for(int i = init; i < max; i++){
if(isPrime(i)){
if(isInclude1949(i)){
System.out.print(""+i+",");
count++;
}
}
}
System.out.println("四位素数有:"+count+"个");
}
}
答案:6
转载请标明出处:http://blog.csdn.net/u012027907
public class Mahu {
void mahu(){
int MAX = 9;
int count = 0;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
for(int a = 1; a <= MAX; a++){
for(int b = 1; b <= MAX; b++){
if(a == b)
continue;
for(int c = 1; c <= MAX; c++){
if(a == c || b == c)
continue;
for(int d = 1; d <= MAX; d++){
if(a == d || b == d || c == d)
continue;
for(int e = 1; e <= MAX; e++){
if(a == e || b == e || c == e || d == e)
continue;
num1 = a*10+b;
num2 = c*100+d*10+e;
num3 = a*100+d*10+b;
num4 = c*10+e;
// System.out.println(a+","+b+","+c+","+d+","+e);
if(num1*num2 == num3*num4){
count++;
System.out.println(""+a+b+"*"+c+d+e);
}
}
}
}
}
}
System.out.println("总数:"+count);
}
}
public class Plant39 {
void plant(){
int MAX = 39;
int m,n;
int sum = 0;
int count = 0;
for(m = 1; m <= MAX; m++){
for(n = 1; n <= MAX; n++){
int tmp = m + n*2;
sum = m + n;
if(tmp == 39 && sum % 2 == 0){
count++;
System.out.println(m+","+n+"");
}
}
}
System.out.println("共有"+count+"种");
}
}
答案:new Rational(ra*x.rb+rb*x.ra,rb*x.rb)
转载请标明出处:http://blog.csdn.net/u012027907