标题:换钱小问题,问题已写,求指教?
只看楼主
zcdjt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:99
专家分:181
注 册:2014-9-9
结帖率:85.71%
已结贴  问题点数:20 回复次数:1 
换钱小问题,问题已写,求指教?
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<body>
    <form action="money.jsp">
        <table>
            <tr>
                <td>应付款:</td>
                <td><input name="number" type="text"></td>
            </tr>
            <tr>
                <td>实际付款:</td>
                <td><input name="number1" type="text"></td>
            </tr>
        </table>
        <input type="submit" value="提交">
    </form>
</body>
</html>


**********************************************************************************************************************
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<body>
    <%
        String s1 = request.getParameter("number");
        String s2 = request.getParameter("number1");
        double m1 = -1;
        double m2 = -1;
        double m3 = -1;
        int i=0;
        if (s1 !=null && s2 !=null) //这个地方输的是数字并不能判断是不是为空,怎样判断输入的是不是数字
                 {
            m1 = Double.parseDouble(s1);
            m2 = Double.parseDouble(s2);
            if (m1 >= 0 && m2 >= 0&&m2>=m1)//这个地方也判断不了m2是否大于m1,m2是必须要大于m1的
                       {
            int y100, y50, y10, y5, y;
            m3 = m2 - m1;
            for (y = 0; y <= m3; y++) {
                for (y5 = 0; y5 <= m3 / 5; y5++) {
                    for (y10 = 0; y10 <= m3 / 10; y10++) {
                        for (y50 = 0; y50 <= m3 / 50; y50++) {
                            for (y100=0;y100<=m3/100;y100++) {
                               if(y+y5*5+y10*10+y50*50+y100*100==m3){
                                 out.println("应该付 :"+"100元"+y100+"张"+","+"50元"+y50+"张"+","+"10元"+y10+"张"+","+
                                 "5元"+y5+"张"+","+"1元"+y+"张"+"<br>");
                                 i++;
                                 }
                            }                           
                        }
                    }
                }
            }
        }
        else{
        out.println("你应付的金额不足");
        }
        out.println("总共有:"+i+"种换法");
    }
   
  else{
        out.println("输入有误,请重新输入:");//我想让输入错误转回money1.jsp怎么弄
      }
     
  
        
    %>
    <jsp:forward page="money1.jsp"/>
</body>
</html>
搜索更多相关主题的帖子: number action import java 
2016-11-02 21:18
xss_wl
Rank: 5Rank: 5
等 级:禁止访问
威 望:3
帖 子:100
专家分:315
注 册:2016-10-15
得分:20 
能不能详细描述一下,你本来想实现什么功能,暂时不涉及代码。
2016-11-03 14:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-470631-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019034 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved