5. ข้อความ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 5-8  โปรแกรมคำนวณเลขโดดตรวจสอบตามมาตรฐาน EAN-13
import java.util.Scanner;
// โปรแกรมคำนวณเลขโดดตรวจสอบตามมาตรฐาน EAN-13
public class EAN13 {
  public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);
    System.out.print("ตัวเลข 12 หลัก = ");
    String d = kb.nextLine();
    int s = 0;
    s += Integer.parseInt(d.substring(0, 1));     // ตำแหน่งคู่ 
    s += Integer.parseInt(d.substring(2, 3));
    s += Integer.parseInt(d.substring(4, 5));
    s += Integer.parseInt(d.substring(6, 7));
    s += Integer.parseInt(d.substring(8, 9));
    s += Integer.parseInt(d.substring(10, 11));
    s += 3 * Integer.parseInt(d.substring(1, 2)); // ตำแหน่งคี่ 
    s += 3 * Integer.parseInt(d.substring(3, 4));
    s += 3 * Integer.parseInt(d.substring(5, 6));
    s += 3 * Integer.parseInt(d.substring(7, 8));
    s += 3 * Integer.parseInt(d.substring(9, 10));
    s += 3 * Integer.parseInt(d.substring(11, 12));
    System.out.println("Check Digit คือ " + ((10-(s%10))%10));
  }
}
©2009 S.Prasitjutrakul