JAVA CCF-201312-2 ISBN号码

欢迎访问我的CCF认证解题目录

题目描述

思路过程

直接求和计算最后判断就好了

代码

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String str = in.next();
		char[] ISBN = {'0','1','2','3','4','5','6','7','8','9','X'};//识别码
		int sum = 0;
		for ( int i = 0, j = 1; i < str.length()-1; i++ ) {
			if ( str.charAt(i) != '-' ) {
				sum += (str.charAt(i)-'0')*j++;//求和
			}
		}
		char c = ISBN[sum%11];//计算识别码
		if ( str.charAt(str.length()-1) == c ) {//判断是否正确
			System.out.println("Right");
		} else {
			System.out.println(str.substring(0, str.length()-1)+c);
		}
	}
	
}
发布了60 篇原创文章 · 获赞 0 · 访问量 2150

猜你喜欢

转载自blog.csdn.net/weixin_43732798/article/details/100709218
今日推荐