家庭收支基础代码
作者:互联网
package project1;
//----------------家庭收支记账软件---------------
// 1.收支明细
// 2.登记收入
// 3.登记支出
// 4.退出
// 请选择1-4:
import java.util.Scanner;
public class Shouzhi {
public static void main(String[] args) {
boolean t=true;
int sum=0;
Scanner s = new Scanner(System.in);
String details="";
while (t) { //循环语句
System.out.println("----------------家庭收支记账软件---------------");
System.out.println("1.收支明细");
System.out.println("2.登记收入");
System.out.println("3.登记支出");
System.out.println("4.退出");
System.out.println("请选择1-4:");
int i = s.nextInt();
switch (i) {
case 1:
System.out.println("收支明细" + "\t" + "总金额" + "\t" + "收支" + "\t" + "原因");
System.out.println(details);
System.out.println("----------------------------------");
break;
case 2:
System.out.println("收入"+"\t"+"原因");
int input = s.nextInt();
sum+=input;
String a = s.nextLine();
System.out.println(input+"\t"+a);
details+=("收入\t"+sum+"\t"+input+"\t"+a+"\n");
break;
case 3:
System.out.println("支出"+"\t"+"原因");
int output = s.nextInt();
sum-=output;
String a1 = s.nextLine();
System.out.println(output+"\t"+a1);
details+=("支出\t"+sum+"\t"+output+"\t"+a1+"\n");
break;
case 4:
System.out.println("退出");
t=false;
break;
default:
System.out.println("输入错误,请重新输入1-4选项");
}
}
}
}
标签:int,代码,System,家庭,println,收支,sum,out 来源: https://www.cnblogs.com/yuhangjie/p/15314857.html