提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建一个程序,将MM / DD / YYYY格式的生日(例如04/29/2016)变成三个单独的字符串。
/**来自 nowjava.com**/ public class Main { public static void main(String[] arguments) { String birthday = "04/29/2016"; String month = birthday.substring(0, 2); String day = birthday.substring(3, 5); String year = birthday.substring(6, 10); System.out.println("Birthday: " + birthday); System.out.println("Month: " + month); System.out.println("Day: " + day); System.out.println("Year: " + year); } }