13-12-02(ISBN号码)

遍历截取字符串的每一位,转化为int之后计算得到结果,再分情况输出以下结果即可

import java.util.*;
public class Main{
public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String str = in.nextLine();

	int n = str.length();
	int sum = 0;
	int j =1;
	for(int i =0;i<n-1;i++){	
		String st = str.substring(i,i+1);
		if(!st.equals("-")) {
			sum += Integer.parseInt(st)*(j++);
		}
	}

	
	int result = sum%11;
	String RESULT = "";
	if(result == 10) {
		RESULT = "X";
	}else {
		RESULT =  result+"";
	}
	if(RESULT.equals(str.substring(n-1, n))) {
		System.out.print("Right");
	}else {
		String S = str.substring(0,n-1)+RESULT;
		System.out.print(S);
	}

}
}

上一篇:js截取字符串


下一篇:java截取字符串笔记