第五题

/**
* @ClassName HomeWork05
* @Description TODO
* @Author Orange
* @Date 2021/4/25 10:09
* @Version 1.0
**/ /*
Notes:
定义一个圆类Circle,定义属性:半径,
提供显示圆周长功能的方法,提供显示圆面积的方法
Define a circle class Circle, define the attribute: radius,
provide a method to display the function of the circumference,
and provide a method to display the area of the circle.
*/
import java.util.Scanner; public class HomeWork05 {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
System.out.println("请输入圆的半径:");
Double radius = myScanner.nextDouble(); //键入半径值 Circle a = new Circle(radius); //创建对象a,并利用构造器对radius赋值 System.out.println("圆的周长为: " + a.perimeter()); //调用对象a的方法perimeter并输出圆周长
System.out.println("圆的面积为: " + a.area()); //调用对象a的方法area并输出圆面积
}
} class Circle {
double PI = 3.14;
double radius; public Circle(double radius) { //构造器
this.radius = radius;
} public Double perimeter () {
Double Circle_perimeter = 2 * PI * this.radius; //计算圆周长
Circle_perimeter = (double) Math.round(Circle_perimeter * 100) / 100; //将double类型转换成保留一位小数
return Circle_perimeter;
} public Double area () {
Double Circle_area = PI * PI * this.radius; //计算圆周长
Circle_area = (double) Math.round(Circle_area * 100) / 100;
return Circle_area;
} } /*
Program running results:
------------------------------------
请输入圆的半径:
10
圆的周长为: 62.8
圆的面积为: 98.6
------------------------------------
*/

第六题

/**
* @ClassName HomeWork06
* @Description TODO
* @Author Orange
* @Date 2021/4/25 13:41
* @Version 1.0
**/ /*
Notes:
编程创建一个Cale计算类,在其中定义2个变量表示两个操作数,
定义四个方法实现求和、差、乘、商(要求除数为0的话,要提示)
并创建两个对象,分别测试。
Create a 'Cale' calculation class programmatically,
define two variables in it to represent two operands,
define four methods to achieve sum, difference, multiplication,
and quotient (if the divisor is required to be 0,
you need to prompt) and create two objects and test separately.
*/ public class HomeWork06 {
public static void main(String[] args) {
A06 a = new A06(4 , 9); //对象a
System.out.println("这两个数的和为:" + a.sum());
System.out.println("这两个数的差为:" + a.difference());
System.out.println("这两个数的积为:" + a.product());
System.out.println("这两个数的除数为:" + a.divisor()); A06 b = new A06(13 , 5); //对象b
System.out.println("这两个数的和为:" + b.sum());
System.out.println("这两个数的差为:" + b.difference());
System.out.println("这两个数的积为:" + b.product());
System.out.println("这两个数的除数为:" + b.divisor());
}
} class A06 {
double num1;
double num2;
double Sum;
double Difference;
double Product;
double Divisor; public A06(double num1, double num2) {
this.num1 = num1;
this.num2 = num2;
System.out.println();
System.out.println("num1 = " + this.num1 + ", num2 = " + this.num2);
} public Double sum() { //求和
Sum = this.num1 + this.num2;
return Sum;
} public Double difference() { //求差
if(this.num1 > this.num2) {
Difference = this.num1 - this.num2;
return Difference;
}else {
Difference = this.num2 - this.num1;
return Difference;
} } public Double product() { //求乘积
Product = this.num1 * this.num2;
return Product;
} public Double divisor() { //求除数
if(this.num1 > this.num2) {
Divisor = this.num1 / this.num2;
}else {
Divisor = this.num2 / this.num1;
}
return Divisor;
} } /*
Program running results:
------------------------------------ num1 = 4.0, num2 = 9.0
这两个数的和为:13.0
这两个数的差为:5.0
这两个数的积为:36.0
这两个数的除数为:2.25 num1 = 13.0, num2 = 5.0
这两个数的和为:18.0
这两个数的差为:8.0
这两个数的积为:65.0
这两个数的除数为:2.6
------------------------------------
*/

第七题

/**
* @ClassName HomeWork07
* @Description TODO
* @Author Orange
* @Date 2021/4/25 16:34
* @Version 1.0
**/ /*
Notes:
设计一个Dog类,有名字、颜色和年龄属性,定义输出方法show()
显示其信息,并创建对象,进行测试【提示:this,属性】
Design a 'Dog' class with attributes of name, color and age,
define the output method show() to display its information,
and create an object for testing [Prompt: this, attribute]
*/ public class HomeWork07 {
public static void main(String[] args) {
Dog d = new Dog("峰哥的狗仔", "水泥灰", 3);
System.out.println("====狗的信息====");
System.out.println("名字: " + d.name );
System.out.println("颜色: " + d.color );
System.out.println("年纪: " + d.age );
}
} class Dog {
String name;
String color;
int age;
public Dog(String name, String color, int age) {
this.name = name;
this.color = color;
this.age = age;
} public void show() {
System.out.println("name = " + this.name + ", color = "
+ this.color + ", age = " + this.age);
}
} /*
Program running results:
------------------------------------
====狗的信息====
名字: 峰哥的狗仔
颜色: 水泥灰
年纪: 3
------------------------------------
*/

第八题

/**
* @ClassName HomeWork08
* @Description TODO
* @Author Orange
* @Date 2021/4/26 8:44
* @Version 1.0
**/ /*
Notes:
给定一个Java程序的代码如下所示,则编译运行后,输出结果是?
public class Test {
int count = 0;
public void count1() {
count = 10;
System.out.println("count1 = " + count);
}
public void count2(){
System.out.println("count1 = " + count++);
} public static void main(String[] args) {
new Test().count1();
Test t1 = new Test();
t1.count2();
t1.count2();
}
} */ public class HomeWork08 {
static int count = 0;
public void count1() {
count = 10;
System.out.println("count1 = " + count);
}
public static void count2(){
System.out.println("count1 = " + count++);
}
public static void main(String[] args) {
new HomeWork08().count1();
HomeWork08 t1 = new HomeWork08();
HomeWork08.count2();
HomeWork08.count2();
}
} /*
Program running results:
------------------------------------
count1 = 10
count1 = 10
count1 = 11
------------------------------------
*/

最新文章

  1. [转]Java中Map的用法详解
  2. think in java学习笔记
  3. 毫米转换为PX
  4. postman-根据接口文档进行测试
  5. cmd实用命令
  6. React生命周期和虚拟DOM
  7. coreOS+Docker新一代企业轻量级Linux
  8. vi set number E486:Pattern not found:
  9. 反序列py脚本分享(原创)
  10. Caffe代码分析--crop_layer.cu
  11. MVC架构中的Repository模式 个人理解
  12. Redhat更换yum源
  13. Eclipse打印GC日志
  14. Bayesian Program Synthesis - 初步探索
  15. [转]gluProject 和 gluUnproject 的详解
  16. C# Redis的操作
  17. 分享个基于 Node.js + React 的博客系统
  18. html的body内标签之label标签和fieldset标签
  19. 贪玩ML系列之CIFAR-10调参
  20. Java多态机制和继承中重写重载

热门文章

  1. zookeeper05Curator
  2. 从实现到原理,聊聊Java中的SPI动态扩展
  3. vue+element 返回数组或json数据自定义某列显示的处理--两种方法
  4. 利用Git+GitHub进行团队协作开发
  5. React中组件之间是如何通信的 react的组件通信方式有哪些
  6. 聊聊最近爆火的 CHAT-GPT
  7. C#/JS 压缩到指定大小的图片 (内存不足问题修改)
  8. PostGIS之Geometry
  9. LeetCode-1996 游戏中弱角色的数量
  10. pat乙级1023 组个最小数