谢谢各位的回复,全角是我打字的疏忽。我写的程序是这样的,但是中间部分太麻烦,所以想简写一下
import javax.swing.*;public class good1 {
public static void main(String args[])
{
String inputString;
int a, b, c, d, e, f, g, h, i, j, X, x, y;     inputString = JOptionPane.showInputDialog("Enter Student ID number" );
X = Integer.parseInt(inputString);
        a = X/100000000;
        b = X/10000000-a*10;
        c = X/1000000-a*100-b*10;
        d = X/100000-a*1000-b*100-c*10;
        e = X/10000-a*10000-b*1000-c*100-d*10;
        f = X/1000-a*100000-b*10000-c*1000-d*100-e*10;
        g = X/100-a*1000000-b*100000-c*10000-d*1000-e*100-f*10;
        h = X/10-a*10000000-b*1000000-c*100000-d*10000-e*1000-f*100-g*10;
        i = X/1-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100-h*10;
        y = b + c + d + e + f + g + h;      if( ( a % i ) == 0 & ( y / 2 ) == 1 )
          JOptionPane.showMessageDialog(null,"Congratulation, your student ID number is valid" );
      else
          JOptionPane.showMessageDialog(null," Sorry, your student ID number is not valid " );
}
}

解决方案 »

  1.   

    如果你的是固定的长度可以这样写
     String X = inputString;
            a = Integer.parseInt(X.substring.(0,1));
            b = Integer.parseInt(X.substring.(1,2));
            c = Integer.parseInt(X.substring.(2,3));
            d = Integer.parseInt(X.substring.(3,4));
            e = Integer.parseInt(X.substring.(4,5));
            f = Integer.parseInt(X.substring.(5,6));
            g = Integer.parseInt(X.substring.(6,7));
            h = Integer.parseInt(X.substring.(7));
      

  2.   

    这是我改好的import javax.swing.*;public class good1 {
    public static void main(String args[])
    {
    String inputString;
    int a, b, c, d, e, f, g, h, i, j,  x, y;     inputString = JOptionPane.showInputDialog("Enter Student ID number" );
     String X = inputString;
            a = Integer.parseInt(X.substring.(0,1));
            b = Integer.parseInt(X.substring.(1,2));
            c = Integer.parseInt(X.substring.(2,3));
            d = Integer.parseInt(X.substring.(3,4));
            e = Integer.parseInt(X.substring.(4,5));
            f = Integer.parseInt(X.substring.(5,6));
            g = Integer.parseInt(X.substring.(6,7));
            h = Integer.parseInt(X.substring.(7,8));
            i = Integer.parseInt(X.substring.(7,8));
            y = b + c + d + e + f + g + h;      if( ( a % i ) == 0 && ( y / 2 ) == 1 )
              JOptionPane.showMessageDialog(null,"Congratulation, your student ID number is valid" );
          else
              JOptionPane.showMessageDialog(null," Sorry, your student ID number is not valid " );
    }
    }