62,615
社区成员
发帖
与我相关
我的任务
分享
public class test36
{
public static void main(String[] args)
{
int pNum ;//pNum为人数
int i;
for( i = 1; ;i++ )
{//i为桌数
pNum = 11*i*10+9;
if(pNum%9==8 && pNum%7 ==6 )
{
break;
}
}
System.out.println("第一种方法计算,桌子数为:"+i+" 人数为:"+pNum);
i=2;
for(; ;i++ )
{ //i为桌数
if(((11*i-8)%9==0) && ((11*i-6)%7 ==0)&&((11*i -4)%5==0)&&((11*i-2)%3==0))
{
break;
}
}
System.out.println("第二种方法计算,桌子数为:"+i+" 人数为:"+11*i);
}
}
public int find(double searchKey)
{
int lowerBound = 0;
int upperBound = nElems-1;
int curIn;
while(true)
{
curIn = (lowerBound + upperBound ) / 2;
if(a[curIn]==searchKey)
return curIn; // found it
else if(lowerBound > upperBound)
return nElems; // can't find it
else // divide range
{
if(a[curIn] < searchKey)
lowerBound = curIn + 1; // it's in upper half
else
upperBound = curIn - 1; // it's in lower half
} // end else divide range
} // end while
} // end find
public class Haniojava
{
public static void main(String args[])
{
byte n=2;
char a='A',b='B',c='C';
hanio(n,a,b,c);
}
public static void hanio(byte n,char a,char b,char c)
{
if(n==1)
System.out.println("move "+a+" to "+b);
else
{
hanio((byte)(n-1),a,c,b);
System.out.println("move "+a+" to "+b);
hanio((byte)(n-1),c,b,a);
}
}
}