Java examples for java.lang:String Algorithm
classify Return Age string
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String birthday = "java2s.com"; System.out.println(classifyReturAge(birthday)); }// w w w . j a v a2 s . co m private static String[] return_age = { "<18", "18-25", "25-40", ">40" }; public static String classifyReturAge(String birthday) { String year = birthday.split("/")[2]; int year_v = Integer.parseInt(year); if (year_v < 18) { return return_age[0]; } else if (year_v >= 18 && year_v < 25) { return return_age[1]; } else if (year_v >= 25 && year_v < 40) { return return_age[2]; } else { return return_age[3]; } } }