java第一个小项目(来源于尚某谷的项目一)---家庭收支记账软件

题目如下:

我的代码如下: 

import java.util.Scanner;
public class family {
    public static void main(String[] args){
        Scanner a=new Scanner(System.in);
        String[] str1=new String[1000];
        String[] str2=new String[1000];
        int[] b=new int[1000];
        b[0]=10000;
        int[] c=new int[1000];
        int count=1;
        while(true) {
            System.out.println("************家庭收支记账软件************\n");

            System.out.println("\t1.收支明细");
            System.out.println("\t2.登记收入");
            System.out.println("\t3.登记支出");
            System.out.println("\t4.退出\n");
            System.out.print("\t请选择(1-4):");
            int n = a.nextInt();
            if(n==4)
                break;
            switch (n) {
                case 1:
                    if (count == 1)
                        System.out.println("对不起,无收支记录");
                    else {
                        System.out.println("************当前收支记录************");
                        System.out.println("收支\t账户金额\t收支金额\t说 明");
                        int i = 0;
                        for (i = 1; i < count; i++) {
                            System.out.println(str1[i] + "\t" + b[i] + "\t        " + c[i] + "\t        " + str2[i]);
                        }

                    }
                    break;
                case 2:
                    System.out.print("请输入收入的金额:");
                    c[count] = a.nextInt();
                    b[count] =b[count-1]+ c[count];
                    System.out.print("请输入费用的说明:");
                    str2[count] = a.next();
                    str1[count] = "收入";
                    count++;
                    break;
                case 3:
                    System.out.print("请输入支出的金额:");
                    c[count] = a.nextInt();
                    b[count] =b[count-1]- c[count];
                    System.out.print("请输入费用的说明:");
                    str2[count] = a.next();
                    str1[count] = "支出";
                    count++;
                    break;
            }
                   }

    }
   
}

 编译结果:

 java小白/*-

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值