当前位置: 首页 > news >正文

星沙网站建设公司百度店面定位怎么申请

星沙网站建设公司,百度店面定位怎么申请,北京市,web端网站开发本文章就讲的是很基础的类的使用 重点大概就是类的构造函数以及一些很基础的东西。 实验内容是些老生常谈的东西,Complex类,在当初学C面向对象的时候也是这个样子展开的。 内容如以下: public class Complex {float real;float imag;public…

本文章就讲的是很基础的类的使用
重点大概就是类的构造函数以及一些很基础的东西。

实验内容是些老生常谈的东西,Complex类,在当初学C++面向对象的时候也是这个样子展开的。
内容如以下:

public class Complex {float real;float imag;public Complex(){real = 0;imag = 0;}public Complex(float real, float imag){this.real = real;this.imag = imag;}public Complex add(float real){this.real += real;return this;}public Complex add(Complex complex){this.real += complex.real;this.imag += complex.imag;return this;}public Complex sub(float real){this.real -= real;return this;}public Complex sub(Complex complex){this.real -= complex.real;this.imag -= complex.imag;return this;}public Complex mul(float real){this.real *= real;this.imag *= real;return this;}public Complex mul(Complex complex){float TheReal = this.real;float TheImag = this.imag;this.real = TheReal * complex.real - TheImag*complex.imag;this.imag = TheReal * complex.imag + TheImag*complex.real;return this;}public String toString(){String str="";if(this.imag == 0){str += this.real;}else if(this.imag > 0 ){if(this.real==0){str += this.imag + "i";}else str += this.real + "+" + this.imag + "i";}else{if(this.real==0){str += this.imag + "i";}else str += this.real + "" + this.imag + "i";}return str;}}

这里也不得不说一丁点相关知识–重载 overload
如这里的:

	public Complex(){real = 0;imag = 0;}public Complex(float real, float imag){this.real = real;this.imag = imag;}public Complex add(float real){this.real += real;return this;}public Complex add(Complex complex){this.real += complex.real;this.imag += complex.imag;return this;}

这里的Complex()Complex(float real, float imag)构造函数也就用了一些重载的知识。
所谓重载,就是函数名不变但是函数内部的参数变化,我们调用函数时通过函数里面的参数决定我们要调用哪个函数。
同理的,Complex add(float real),Complex add(Complex complex)也是如此,当add()的括号里面是一个float值的时候调用Complex add(float real),括号里面是一个Complex对象的时候调用Complex add(Complex complex)
我当时认为这不是理所当然的吗?其实不是的,这里是用到了重载(overload)的知识。
总代码:
在这里插入图片描述

包com.Class.Work3里的Complex类:

package com.Class.Work3;public class Complex {float real;float imag;public Complex(){real = 0;imag = 0;}public Complex(float real, float imag){this.real = real;this.imag = imag;}public Complex add(float real){this.real += real;return this;}public Complex add(Complex complex){this.real += complex.real;this.imag += complex.imag;return this;}public Complex sub(float real){this.real -= real;return this;}public Complex sub(Complex complex){this.real -= complex.real;this.imag -= complex.imag;return this;}public Complex mul(float real){this.real *= real;this.imag *= real;return this;}public Complex mul(Complex complex){float TheReal = this.real;float TheImag = this.imag;this.real = TheReal * complex.real - TheImag*complex.imag;this.imag = TheReal * complex.imag + TheImag*complex.real;return this;}public String toString(){String str="";if(this.imag == 0){str += this.real;}else if(this.imag > 0 ){if(this.real==0){str += this.imag + "i";}else str += this.real + "+" + this.imag + "i";}else{if(this.real==0){str += this.imag + "i";}else str += this.real + "" + this.imag + "i";}return str;}}

调用Complex类的TestWork3类:

import com.Class.Work3.Complex;public class TestWork3 {public static void main(String[] args) {Complex c = new Complex(1, 2);
//        c.add(5);
//        Complex w = new Complex(4,1);
//        c.sub(w);
//        Complex w2 = new Complex(1,2);
//        c.mul(w2);
//        c.mul(5);System.out.println(c);}
}

就这样了~

http://www.rdtb.cn/news/17447.html

相关文章:

  • 学做网站要多久多少钱短视频营销成功案例
  • 提供东莞网站制作公司免费域名申请网站大全
  • 最低价网首页重庆百度整站优化
  • 河南如何做网站武汉seo推广
  • 网站建设任务平台100种宣传方式
  • 在北京网站建设的岗位关键词优化的方法有哪些
  • linux中怎么打开wordpress苏州seo优化
  • 上百度推广 免费做网站重庆放心seo整站优化
  • 个人网站建站seod的中文意思
  • 珠海有什么网站青岛快速排名优化
  • 美工好的网站谷歌浏览器app下载安装
  • 品牌的佛山网站建设网络营销策略的演变
  • 免费试用网站空间推广软件一键发送
  • 中国最早做网站是谁郑州网络推广方案
  • 做墙报的网站永久免费建站系统
  • pc做网站服务器吗seo推广网址
  • 空调维修网站建设seo优化快速排名技术
  • 做塑料哪个网站好中山360推广
  • 什么网站做任务的q币百度推广手机登录
  • 做图的模板下载网站百度推广授权代理商
  • 网站做整站做优化关键词排名怎么做上去
  • 网站建设 上海交大外贸营销网站制作
  • 淘宝网站怎么做视频教程拉人注册给佣金的app
  • wordpress多个文章页长沙企业seo服务
  • 做有色研究的网站优秀的软文广告案例
  • 深圳营销型网站建设多少钱无锡网站建设优化公司
  • 手机能用的网站sem优化托管
  • 江门建站模板网络营销产品
  • 访问网站提示输入用户名密码seo是什么及作用
  • 学校网站建设申请报告今天国内新闻10条