今天简单做小系统,之前也做过的类似的系统,想重新复习一次逻辑业务(2023-02-01-16:10:49)
这次学到有了一个小的函数
//获取本地时间并将时间格式化,调用sdf.format(date)输出 Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM--dd HH:mm");
System.out.printfln(sdf.format(date)//格式输出时间:2023-02--01 16:10
);
package JavaLearn.SmallChangeSys; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class SmallChange { public static void main(String[] args) { boolean loop=true; Scanner scanner = new Scanner(System.in); String key=""; String details="======零钱明细========"; double money=0; double balance=0; //获取本地时间并将时间格式化,调用sdf.format(date)输出 Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM--dd HH:mm"); String note=""; //do-wwhiel循环使用,设定退出字符变量 do { System.out.println("\n======欢迎使用零钱通========"); System.out.println("\t\t\t1 零钱明细"); System.out.println("\t\t\t2 收益入账"); System.out.println("\t\t\t3 消费"); System.out.println("\t\t\t4 退出系统"); System.out.println("请输入选项"); key=scanner.next(); switch (key){ case "1": System.out.println(details); break; case "2": System.out.println("请输入收入金额"); money=scanner.nextDouble(); //判断不符合的条件 if(money<=0){ System.out.println("入账金额应大于0元"); break; } balance+=money; details+="\n收益入账\t+"+money+"\t"+sdf.format(date)+"\t余额:"+balance; break; case "3": System.out.println("请输入消费金额"); money=scanner.nextDouble(); if(money<=0||money>balance){ System.out.println("入账金额在0-"+balance); break; } System.out.println("请输入消费说明"); note=scanner.next(); balance-=money; details+="\n"+note+"\t-"+money+"\t"+sdf.format(date)+"\t余额:"+balance+"元"; break; case "4": String flag=""; //用while限制输出 while(true){ System.out.println("确认退出:是:y 否:n"); flag=scanner.next(); if("y".equals(flag)||"n".equals(flag)) break; } //判断意愿 if("y".equals(flag)){ loop=false; break; } else if ("n".equals(flag)) { break; } default: System.out.println("输入有误,请重新选择"); } }while(loop); System.out.println("已退出-----"); } }
标签:break,Java,09,System,学习,date,sdf,println,out From: https://www.cnblogs.com/copyjames/p/17083192.html