保龄球得分计算代码

保龄球得分计算代码

示例: 全中 = x, 补中 = 9/ , 不中 = -

public static void main(String[] args) {
	sum();
}
// 汇总结果
public static void sum(){
	//String scan="xxxxxxxxxxxx";
	//String scan="9/9/9/9/9/9/9/9/9/9/9";
	String scan="x9/x81x7/9-8/72xx8";
	//String scan="7-8/9/x8-xxx8/9/8";
	//String scan="----------";
	
	char [] ch=scan.toCharArray();
	/* 依次为
	 * 统计结果
	 * 轮次----10轮次为一局
	 * */
	int result=0;
	int lunci=0;
	
	for (int i = 0; i < ch.length; i++) {
		// 1~9 lunci
		if(lunci<9){
			if(ch[i]=='x'){
				result=result+xbc(ch[i],ch[i+1],ch[i+2]);
			}
			else if(ch[i+1]=='/'){
				result=result+abc(ch[i],ch[i+1],ch[i+2]);
				i++;
			}
			else{
				result=result+ab(ch[i],ch[i+1]);
				i++;
			}
			System.out.println("result="+result);
			lunci++;
		}
		// 10 lunci
		if(lunci==9){
			i++;
			if(ch[i]=='x'){
				result=result+xbc(ch[i],ch[i+1],ch[i+2]);
			}
			else if(ch[i+1]=='/'){
				result=result+abc(ch[i],ch[i+1],ch[i+2]);
			}
			else{
				result=result+ab(ch[i],ch[i+1]);
			}
			System.out.println("result="+result);
			break;
		}
	}
	System.out.println("endResult="+result);
	
}

/*char a,char b,char c
 * a=x
 * x,b,c
 * */
public static int xbc(char a,char b,char c){
	int rs=0;
	if(c=='/'){
		rs=20;
	}
	else{
		rs=10+change(b)+change(c);
	}
	return rs;
}


/*char a,char b,char c
 * b=/
 * a,b and c
 * */
public static int abc(char a,char b,char c){
	int rs=10+change(c);
	return rs;
}
/*char a,char b
 * a+b<10
 * a , b
 * */
public static int ab(char a,char b){
	int rs=change(a)+change(b);
	return rs;
}

// char---int
public static int change(char a){
	if(a=='x'){
		return 10;
	}
	else if(a=='-'){
		return 0;
	}
	else{
		int i=Integer.parseInt(a+"");
		return i;
	}
}
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值