java篮球_篮球积分Java程序?

因为这是家庭作业答案在最后,我希望你不需要它。

只读了几行的时间,尽量看你怎么一点需要阅读之前你看着办吧YOURSELF

假设你有一个点的数量,作为一个例子,让我们做points=16。

1.多少个三分球?

您可以从points多少个三个指针?那么,最多points/3.0=5.333。让我们把这个下降到5。在一般情况下:

int maxThreePointers=points/3;

java中的整数运算自动舍入。现在我们知道三个指针的数量必须在0 .. maxThreePointers的范围内。现在我们知道很多!

2.有多少实地目标?

接任何的三个指针数从上述范围内,作为一个例子,让我们做的情况下threePointers = 2。考虑剩下要分发的点数。在我们的案例中为int pointsMissing = points - threePointers*3;pointsMissing = 16 - 2*3 = 10。

冲洗并重复第一个想法:我们现在有10分,我们可以有多少场目标? int maxFieldGoals = pointsMissing/2;,即在示例中的0和5之间。

3.犯规次数多少?

挑选任意来自上述范围的三个指针和字段目标的数量。保留点必须是恶意目标。完成!

这可以在一组嵌套的循环进行编码:

扰流壁

扰流壁

扰流壁

扰流壁

扰流壁

扰流壁

扰流板壁上

扰流板壁上

int points = 16; // read this from stdin.

int maxThreePointers = points/3;

int count = 0;

for(int threePointers = 0; threePointers <= maxThreePointers; threePointers++){

int remainingPoints = points - threePointers*3;

int maxFieldGoals = remainingPoints/2;

for(int fieldGoals = 0; fieldGoals <= maxFieldGoals; fieldGoals ++){

// last one is easy!

int foulShots = remainingPoints - fieldGoals*2;

count++;

System.out.println(threePointers + " three pointers, " + fieldGoals + " field goals and " + foulShots + " foul shots");

}

}

System.out.println("There are " + count + " ways to score " + points + " points");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值