不知为何有的对,有的却错,请求帮助

P1055 [NOIP2008 普及组] ISBN 号码

派大星Magic @ 2022-01-19 18:11:42

Jim 18:08:35

import java.util.Scanner;

public class Main {
     public static void main(String[] args) {
         String  isbn = new String ();

         char isbn1;
         String isbn2 = new String();
         String isbn3 = new String();
         char isbn4;
         int isbnS1,isbnS2,isbnS3,isbnS4;
         int sum = 0;
         Scanner scan = new Scanner(System.in);
         isbn = scan.next();

         isbn1 = isbn.charAt(0);
         isbn2 = isbn.substring(2, 5);
         isbn3 = isbn.substring(6, 11);
         isbn4 = isbn.charAt(12);

         isbnS1 = Integer.parseInt(String.valueOf(isbn1)); 
         isbnS2 = Integer.parseInt(isbn2);
         isbnS3 = Integer.parseInt(isbn3);
         isbnS4 = Integer.parseInt(String.valueOf(isbn4)); 

         Dome test = new Dome();
         isbnS1 = isbnS1 * 1;
         isbnS2 = test.zhuanhua(isbnS2,4);
         isbnS3 = test.zhuanhua(isbnS3,9);

         sum = isbnS1 + isbnS2 + isbnS3;
         sum = sum % 11;

         if(sum == isbnS4) {
             System.out.println("Right");
         }else {

             System.out.println(isbn.substring(0, 12) + sum);
         }
    }
}
class Dome{
    public int zhuanhua(int number,int digirt) {

        int temp = 0;
        int sum = 0;
        while(number > 0) {
            if(number/10 != 0) {
                temp = number % 10;
                sum += temp * digirt;
                digirt --;
                number = number/10;

            }else {
                sum += number * digirt;
                number = number/10;
                digirt --;
            }
        }

        return sum;
    }
}

|