分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

Class.jsp

发布时间:2023-09-06 02:36责任编辑:傅花花关键词:jsjsp
<%@page import="java.util.Random"%><%@ 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>class</title></head><%!public class people//定义一个people类{ ???int height;//身高 ???char name;//呢称 ???//默认构造函数 ???public people(){ ???????height=(int)(Math.random()*40+160); ???????name=(char)(int)(Math.random()*26+‘a‘); ???} ???//有参构造函数 ???public people(int height,char name){ ???????this.height=height; ???????this.name=name; ???} ???//计算标准体重 ???public double getWeight(){ ???????return (this.height-150)*0.6+48; ???} ???//获取身高 ???public double getHeight(){ ???????return this.height; ???} ???//获取呢称 ???public char getName(){ ???????return this.name; ???}}%><body><%//定义两个对象 小红 小明people xiaoming=new people();people xiaohong=new people();//输出小明呢称、身高及标准体重out.print("xiaoming name:"+xiaoming.getName()+"<br>");out.print("xiaoming height:"+xiaoming.getHeight()+"cm<br>");out.print("xiaoming weight:"+xiaoming.getWeight()+"kg<br>");//输出小红呢称、身高及标准体重out.print("xiaohong name:"+xiaohong.getName()+"<br>");out.print("xiaohong height:"+xiaohong.getHeight()+"cm<br>");out.print("xiaohong weight:"+xiaohong.getWeight()+"kg<br>");%></body></html>

Class.jsp

原文地址:https://www.cnblogs.com/sancha/p/10610511.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved