• 基于Java的长整数加减法算法设计


    目 录

    1. 前言 1

    2. 需求分析 1

    3. 概要设计 2

    4. 详细设计 4

    5. 测试 11

    6. 总结 13

    参考文献 15

    附录 15
    2.需求分析
    本产品是作为一个形如计算器的程序首先,需要考虑的就是面向用户操作,由于在使用过程中,用户可能不限于使用电脑,手机等设备进行长整数运算,并且如果用户并没有安装环境那么会照成代码无法运行的情况,为了避免这些平台兼容问题,和方便用户操作,可以采用更方便的网页方式面向用户,在美观简洁的同时,满足人际友好交互。
    在解决了平台兼容问题以后,我们还需要对功能进行设计。
    首先是基本功能:
    1.作为长整数加减法,要实现任意唱的整数的加、减法运算。以用户和计算机对话的方式,即用户根据网页对话框显示的提示信息之后,由用户通过键盘,输入演示程序用规定的运算命令,然后返回结果提示。
    2.我们的长整数计算器,的集合元素限定了用户的输入的字符只能是[‘0’~‘9’],逗号,以及‘+’和‘-’。否则应该提示用户输入的字符串不符合程序的默认要求,并且需要重新输入。
    3.对于输入的数字方面,本文转载自http://www.biyezuopin.vip/onews.asp?id=15262按照中国对长整数的表示习惯,每四位是一组,组间用逗号隔开
    其次是输入和输出结果:
    例如:
    (1)0;0;应输出“0”
    (2)-2345,6789;-7654,3211;应输出“-1,0000,0000”
    (3)-9999,9999;1,0000,0000,0000;应输出“9999,0000,0001”
    ####(4)1,0001,0001;-1,0001,0001;应输出“0”
    ###(5)1,0001,0001;-1,0001,0000;应输出“1”
    (6)-9999,9999,9999;-9999,9999,9999;应输出“-1,9999,9999,9998”
    (7)1,0000,9999,9999;1;应输出“1,0001,0000,0000”
    3.概要设计
    使用技术:数据结构-链表,JAVA基础语法。

    package com.itcast.controller;
    
    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.itcast.service.algorithmService;
    import com.itcast.service.impl.algorithmServiceImpl;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    import org.springframework.web.bind.annotation.*;
    import org.junit.Test;
    
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpServletResponseWrapper;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * Topic:
     *
     * @Author:Pinkman
     * @Date:2021/5/25 22:11
     * @Tips:
     */
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(value = {"classpath:applicationContext.xml"})
    @RequestMapping("/quick")
    @org.springframework.stereotype.Controller
    public class Controller {
    
    
        @Autowired
        @Qualifier("algorithmService")
        algorithmServiceImpl algorithmServicimpl ;
    
    
    
    
        @RequestMapping(value="/sum")
        @ResponseBody
        public String sum(String[] lists) throws IOException {
    
            String total = "0";
    
            //判断新添加的元素格式是否正确
            boolean if_correct = algorithmServicimpl.if_correct(lists[lists.length - 1]);
    
            String ifcorrect ="";
    
            if (if_correct==true) {
                ifcorrect = "1";
            }
            if(if_correct==false){
                ifcorrect = "0";
            }
            for (int i = 0; i  map = new HashMap();
            map.put("data",total);
            map.put("ifcorrect",ifcorrect);
    
            ObjectMapper mapper = new ObjectMapper();
            String s = mapper.writeValueAsString(map);
    
            return s ;
    
        }
    /*
    9999,1 报错 空指针
     */
        @Test
        public void test() throws JsonProcessingException {
            String[] lists = new String[] {"1,1234,1234","1234,1234"};
    
    
            String total = "0";
    
            //判断新添加的元素格式是否正确
            boolean if_correct = algorithmServicimpl.if_correct(lists[lists.length - 1]);
            String ifcorrect ="";
            if (if_correct==true) {
                ifcorrect = "1";
            }
            if(if_correct==false){
                ifcorrect = "0";
            }
    
    
            for (int i = 0; i  map = new HashMap();
            map.put("data",total);
            map.put("ifcorrect",ifcorrect);
    
            ObjectMapper mapper = new ObjectMapper();
            String s = mapper.writeValueAsString(map);
    
            System.out.println(s);
    
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    “全民创业”热潮,现在是不是创业的好时机?可以做什么项目?
    Python Http请求和HTML的解析
    GAN入门|第二篇:人脸图像生成(DCGAN)
    python 中__init__ 作用
    执行shell脚本插入oracle数据库中文数据乱码
    进程控制详解
    Mysql的优化<showprofile>
    【STL编程】【竞赛常用】【part 1】
    什么是B+树,和B树有什么不同?
    LVS负载均衡集群
  • 原文地址:https://blog.csdn.net/sheziqiong/article/details/126722150