java面試趣味程式

來源:互聯網
上載者:User

標籤:sof   print   strong   程式   葡萄酒   bsp   out   nts   final   

一 泊松分酒
1.有一個12品脫的酒瓶,裡面裝滿葡萄酒,另有8品脫和5品脫的瓶子各一個,問如何分出6品脫的酒出來

public class Poissonpointsofwine
{
static final int L=12; //大屏容量
static final int M=8;
static final int S=5;
static int l=12; //大瓶實際酒量
static int m=0;
static int s=0;




static void LintoM()
{
if(l>M)
{
m=M;
}else
{
m=l;
}
l=l-m;
System.out.printf("\nl->m:\t l=%d\tm=%d\ts=%d\t",l,m,s);
}
static void MintoS()
{
int n=s;
if(m+s>s)
{
s=S;
m=m-(S-n);
}else
{
s=S;
m=0;
}
l=l-m;
System.out.printf("\nm->s:\t l=%d\tm=%d\ts=%d\t",l,m,s);
}
static void SintoL()
{
l=l+s;

s=0;
System.out.printf("\ns->l:\t l=%d\tm=%d\ts=%d\t",l,m,s);
}
public static void main(String[] args)
{
while(l!=L/2)
{
if(M==0)
{
LintoM();
}
if(s==S)
{
SintoL();
}else if(m!=0)
{
MintoS();
}
}

}
}

 

 

 

java面試趣味程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.