一道简单的逻辑题

一道简单的逻辑题

要求:斯诺克台球共有21个球,其中有15个红色一分球,另有其它颜色的2,3,4,5,6,7分球各一个,规则是先打一个红色球,然后可以打一个其他分值的球,如此反复,如果台面还有红色球,打入的高分球计分,同时拿出来放回原位置,当打入最后一个红球后再去打其它色球时,那个色球同样要拿出来放回原位,接着按照分数由低到高,分别将2到7分的各色球打尽.要求写一段简单的java函数,实现输入台面上剩余球的数目,计算出可得的最高分。(不考虑罚分等特殊情况)
作算术分析:每打一个红球和一个色球能得到的最高分值是1+7=8分,全部红球打尽所得最高分值:15*8=120分,再加上其它色球的总分值:120+2+3+4+5+6+7=147分.至于怎么样实现输入球数就能得到最高分值嘛,
public class CountMaxScore{
               public int CountMaxScore(int ballnum){//计算最高得分
                              int max = 0;                          //
                              int ball = ballnum;                  //ballnum 传入的剩下的球数.
                              if(ball <= 6){                        //
                                     max = (21 - ball) * 8;
                                     return max;
                              }else{
                                 max  = 15 * 8;
                                 if(int i = 2;i <= (7-ball);i++){
                                             max = max + i;
                                 }
                                    return max;
                                }
               }
              static public void main(String[] args){
                        CountMaxScore msc  = new CountMaxScore();
                         BufferReader in = new BufferReader(new InputStreamReader(System.in));
                           try{
                                 String s = in.ReadLine();
                                 int ball = Integer.parseInt(s);
                                 maxscor = msc.CountMaxScore(ball);
                                 System.out.println("桌面上剩下"+ball+"个球时,选手的最高得分可达:"+maxscore+"分");
                                 }catch(Exception e){}
               }
}

你可能感兴趣的:(一道简单的逻辑题)