import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String id = sc.next();
int a = 0; //英文字母轉數字
char isId[] = new char[id.length()]; //把字串轉維字元
int n2[] = new int[id.length()]; //把除了第一個英文字母的數字放進int裡
for(int i = 0; i < id.length(); i++){ //把字串轉字元
isId[i] = id.charAt(i);
if(i >= 1){ //不包含英文字母放進n2裡
n2[i-1] = id.charAt(i)-'0'; //-字元'0' 回複成原數字
}
}
//字母轉數字
char[] check = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int[] n1 ={ 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30,
31, 33 };
for(int i = 0; i < check.length; i++){
if(isId[0] == check[i]){
a = n1[i];
}
}
int firstNumber = a/10;
int secondNumber = a%10;
int q =firstNumber+secondNumber*9+n2[0]*8+n2[1]*7+n2[2]*6+n2[3]*5+n2[4]*4+n2[5]*3+n2[6]*2+n2[7]*1+n2[8];
if(q%10 == 0){
System.out.println("real");
}else{
System.out.println("fake");
}
}
}
}
請問直接這樣寫可以嗎
public class a001{
public static void main(String[] args) {
java.util.Scanner scanner = new java.util.Scanner(System.in);
String[] en= {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int[] ma= {10,11,12,13,14,15,16,17,34,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33};
String[] input=new String[10];
int ten,zero,all=0;
for(int i=0;i<10;i++) {
input[i]=scanner.next();
for(int j=0;j<25;j++) {
if(input[0]==en[j]) {
ten=ma[j]/10;
zero=ma[j]%10;
all=ten+zero*9;
System.out.print(all);
}
}
}
}
}
import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String id = sc.next();
int a = 0; //英文字母轉數字
char isId[] = new char[id.length()]; //把字串轉維字元
int n2[] = new int[id.length()]; //把除了第一個英文字母的數字放進int裡
for(int i = 0; i < id.length(); i++){ //把字串轉字元
isId[i] = id.charAt(i);
if(i >= 1){ //不包含英文字母放進n2裡
n2[i-1] = id.charAt(i)-'0'; //-字元'0' 回複成原數字
}
}
//字母轉數字
char[] check = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int[] n1 ={ 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30,
31, 33 };
for(int i = 0; i < check.length; i++){
if(isId[0] == check[i]){
a = n1[i];
}
}
int firstNumber = a/10;
int secondNumber = a%10;
int q =firstNumber+secondNumber*9+n2[0]*8+n2[1]*7+n2[2]*6+n2[3]*5+n2[4]*4+n2[5]*3+n2[6]*2+n2[7]*1+n2[8];
if(q%10 == 0){
System.out.println("real");
}else{
System.out.println("fake");
}
}
}
}
轉換型別看不懂