package maple.basic;
import java.util.Scanner;
public class number8 {
//zj a020
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String[] tmp=sc.next().split("");
int sum=number8.turn(tmp[0]);
int i=8;
for(int j=1;j<=8;j++)
{
sum+=i*Integer.parseInt(tmp[j]);
i--;
}
sum+=Integer.parseInt(tmp[9]);
if(sum%10==0)
System.out.println("real");
else
System.out.println("fake");
}
sc.close();
}
static int turn(String str){
String tmp = null;
switch(str) { //地區編號轉數字
case "A":
tmp="10";
break;
case "B":
tmp="11";
break;
case "C":
tmp="12";
break;
case "D":
tmp="13";
break;
case "E":
tmp="14";
break;
case "F":
tmp="15";
break;
case "G":
tmp="16";
break;
case "H":
tmp="17";
break;
case "I":
tmp="34";
break;
case "J":
tmp="18";
break;
case "K":
tmp="19";
break;
case "L":
tmp="20";
break;
case "M":
tmp="21";
break;
case "N":
tmp="22";
break;
case "O":
tmp="35";
break;
case "P":
tmp="23";
break;
case "Q":
tmp="24";
break;
case "R":
tmp="25";
break;
case "S":
tmp="26";
break;
case "T":
tmp="27";
break;
case "U":
tmp="28";
break;
case "V":
tmp="29";
break;
case "W":
tmp="32";
break;
case "X":
tmp="30";
break;
case "Y":
tmp="31";
break;
case "Z":
tmp="33";
break;
}
String[] a=tmp.split("");
int x=Integer.parseInt(a[0]),y=Integer.parseInt(a[1]);
int num=x+(y*9);
return num;
}
}
如題 我在eclipse跑都很正常,可是在這邊就會出錯是為什麼?
package maple.basic;
import java.util.Scanner;
public class number8 {
//zj a020
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String[] tmp=sc.next().split("");
int sum=number8.turn(tmp[0]);
int i=8;
for(int j=1;j<=8;j++)
{
sum+=i*Integer.parseInt(tmp[j]);
i--;
}
sum+=Integer.parseInt(tmp[9]);
if(sum%10==0)
System.out.println("real");
else
System.out.println("fake");
}
sc.close();
}
static int turn(String str){
String tmp = null;
switch(str) { //地區編號轉數字
case "A":
tmp="10";
break;
case "B":
tmp="11";
break;
case "C":
tmp="12";
break;
case "D":
tmp="13";
break;
case "E":
tmp="14";
break;
case "F":
tmp="15";
break;
case "G":
tmp="16";
break;
case "H":
tmp="17";
break;
case "I":
tmp="34";
break;
case "J":
tmp="18";
break;
case "K":
tmp="19";
break;
case "L":
tmp="20";
break;
case "M":
tmp="21";
break;
case "N":
tmp="22";
break;
case "O":
tmp="35";
break;
case "P":
tmp="23";
break;
case "Q":
tmp="24";
break;
case "R":
tmp="25";
break;
case "S":
tmp="26";
break;
case "T":
tmp="27";
break;
case "U":
tmp="28";
break;
case "V":
tmp="29";
break;
case "W":
tmp="32";
break;
case "X":
tmp="30";
break;
case "Y":
tmp="31";
break;
case "Z":
tmp="33";
break;
}
String[] a=tmp.split("");
int x=Integer.parseInt(a[0]),y=Integer.parseInt(a[1]);
int num=x+(y*9);
return num;
}
}
如題 我在eclipse跑都很正常,可是在這邊就會出錯是為什麼?
int sum=number8.turn(tmp[0]);
tmp[0] 是空值,會造成 java.lang.NullPointerException