| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2055 人关注过本帖
标题:换钱小问题,问题已写,求指教?
取消只看楼主 加入收藏
zcdjt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:99
专家分:181
注 册:2014-9-9
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:0 
换钱小问题,问题已写,求指教?
<%@ 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
快速回复:换钱小问题,问题已写,求指教?
数据加载中...
 
   



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

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