标签:rgba double public input body span style price reg
<%@ page language="java" contentType="text/html" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="java.util.regex.Pattern"%> <%@ page import ="java.util.regex.Matcher"%> <!DOCTYPE html> <html> <head> </head> <%! public double getPriceSum(String input){ Pattern pattern; Matcher matcher; String regex="-?[0-9][0-9]*[.]?[0-9]*"; pattern = Pattern.compile(regex); matcher = pattern.matcher(input); double sum=0; while(matcher.find()){ String str = matcher.group(); sum+=Double.parseDouble(str); } return sum; } %> <body bgcolor=cyan> <p style ="font-family:黑体;font-size:20"> <br>张三的菜单:</br> <%String str= "麻婆豆腐:20.6元,红烧肉:68.9元"; %> <br><%=str%></br> <br><b><i>消费总和:<%=getPriceSum(str) %></i></b></br> <br>李四的菜单:</br> <%str= "剁椒鱼头:62.9元,烤鸭:199元,红焖大虾:289.9元"; %> <br><%=str %></br> <br><b><i>消费总和:<%=getPriceSum(str) %></i></b></br> </p> </body> </html>
标签:rgba double public input body span style price reg
原文地址:https://www.cnblogs.com/zxp-0101/p/14589418.html