public class enums {
public static String enumValue(String type) {
String val = "";
String[] origins = {"VISIT", "RECOMMEND", "LEAFLET", "ACTIVITY", "MEDIA", "MESSAGE", "NET", "PHONESALE", "FRIENDS", "OTHERS"};
String[] educations = {"DOCTOR", "POST_GRADUATE", "COLLEGE", "JUNIOR_COLLEGE", "HIGH_SCHOOL", "MIDDLE_SCHOOL", "SECONDARY_SCHOOL"};
if (type.equalsIgnoreCase("origin")) {
val = origins[(int) (Math.random() * origins.length)];
} else if (type.equalsIgnoreCase("education")) {
val = educations[(int) (Math.random() * educations.length)];
}
return val;
}
public static void main(String[] args) {
String sourceId = enumValue("educations");
System.out.println("名单来源是"+sourceId);
}
}
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static String enumValue(String type) {
String val = "";
String[] origins = {"VISIT", "RECOMMEND", "LEAFLET", "ACTIVITY", "MEDIA", "MESSAGE", "NET", "PHONESALE", "FRIENDS", "OTHERS"};
String[] educations = {"DOCTOR", "POST_GRADUATE", "COLLEGE", "JUNIOR_COLLEGE", "HIGH_SCHOOL", "MIDDLE_SCHOOL", "SECONDARY_SCHOOL"};
if (type.equalsIgnoreCase("origin")) {
val = origins[(int) (Math.random() * origins.length)];
} else if (type.equalsIgnoreCase("education")) {
val = educations[(int) (Math.random() * educations.length)];
}
return val;
}
public static void main(String[] args) {
String sourceId = enumValue("education");
System.out.println("名单来源是"+sourceId);
}
}
education多了一个s
名单来源是DOCTOR
俩数组是origins和educations,比较时候的数组是type.equalsIgnoreCase("origin")和type.equalsIgnoreCase("education"),改为以下代码:
public class enums {
public static String enumValue(String type) {
String val = "";
String[] origins = {"VISIT", "RECOMMEND", "LEAFLET", "ACTIVITY", "MEDIA", "MESSAGE", "NET", "PHONESALE", "FRIENDS", "OTHERS"};
String[] educations = {"DOCTOR", "POST_GRADUATE", "COLLEGE", "JUNIOR_COLLEGE", "HIGH_SCHOOL", "MIDDLE_SCHOOL", "SECONDARY_SCHOOL"};
if (type.equalsIgnoreCase("origins")) {
val = origins[(int) (Math.random() * origins.length)];
} else if (type.equalsIgnoreCase("educations")) {
val = educations[(int) (Math.random() * educations.length)];
}
return val;
}
public static void main(String[] args) {
String sourceId = enumValue("educations");
System.out.println("名单来源是"+sourceId);
}
}