Scanner input = new Scanner(System.in); System.out.println("请输入一串数字:"); String number = input.next(); StringBuffer strb = new StringBuffer(number); System.out.println("请输入添加数字:"); String number2 = input.next(); strb.append(number2); for(int i=3;i<(number+number2).length()+(number+number2).length()/3;i=i+4) { strb.insert(i, ","); } System.out.println(strb);
import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] args) { Date date=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String now=format.format(date); System.out.println(now); } }
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Test { public static void main(String[] args) { Calendar cal=Calendar.getInstance(); cal.set(2015,4-1,6); Date date=cal.getTime(); SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); String now=format.format(date); System.out.println(now); System.out.println(now+"是2015年的第"+cal.get(Calendar.WEEK_OF_YEAR)+"周"); System.out.println(now+"是2015年的第"+cal.get(Calendar.DAY_OF_YEAR)+"天"); } }