码迷,mamicode.com
首页 > 编程语言 > 详细

java面试趣味程序

时间:2017-03-25 16:40:19      阅读:163      评论:0      收藏:0      [点我收藏+]

标签: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面试趣味程序

标签:sof   print   strong   程序   葡萄酒   bsp   out   nts   final   

原文地址:http://www.cnblogs.com/zxl1/p/6617353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!