switch语句

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch表单</title>
</head>
<body>
<DIV ALIGN="center">
将学生成绩由百分制转换成5分制<br><br>
<form action="switch.jsp">
请输入成绩:<input type=text name="score"><br><br>
<input type=submit value=提交>
<input type=reset value=重填>
</form>
</DIV>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>switch</title>
</head>
<body>
<%
int score=Integer.parseInt(request.getParameter("score"));//获取表单成绩

switch(score/20){
case 0:
    out.print(0);
    break;
    
case 1:
    out.print(1);
    break;
    
case 2:
    out.print(2);
    break;
    
case 3:
    out.print(3);
    break;
    
case 4:
    out.print(4);
    break;
    
case 5:
    out.print(5);
    break;
default:
    out.print("分数输入有误");
    break;
}
%>
</body>
</html>

 

posted @ 2019-03-27 21:07  三茶散茶  阅读(127)  评论(0)    收藏  举报