第六次作业--static关键字、对象
2024-09-02 01:39:25
##题目一
##Computer
package Train.Method.TeachDemo.Thread.Fuction; /**
* 求n的阶乘算法
* @author 喵
* @date 2019年9月18日下午1:19:34
*/
public class Computer {
public int num; public Computer() {
} public Computer(int num) {
this.num = num;
} public long counter() {
long sum = 1;
for (int i = 1; i <= num; i++) {
sum = sum * i;
}
return sum;
}
}
##Test
package Train.Method.TeachDemo.Thread.FuctionTest;
import Train.Method.TeachDemo.Thread.Fuction.Computer; import java.util.Scanner; import Train.Method.TeachDemo.Thread.Fuction.Computer;
/**
* Test
* @author 喵
* @date 2019年9月18日下午8:08:53
*/
public class ComputerTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入一个整数:");
int num = input.nextInt(); Computer t = new Computer(num);
System.out.println(t.counter());
}
}
##题目二
##MyPoint
/**
* 坐标类
*
* @author 喵
* @date 2019年9月18日下午8:12:32
*/
public class MyPoint {
private int x;
private int y; public MyPoint() { } public MyPoint(int x, int y) {
this.x = x;
this.y = y;
} public int getX() {
return x;
} public void setX(int x) {
this.x = x;
} public int getY() {
return y;
} public void setY(int y) {
this.y = y;
} public static double distance(MyPoint p1, MyPoint p2) {
int xside = Math.abs(p1.x - p2.x);
int yside = Math.abs(p1.y - p2.y);
double temp = Math.pow(xside, 2) + Math.pow(yside, 2);
return (Math.sqrt(temp));
}
}
##Test
import java.util.Scanner; /**
* 测试点距离类
* @author 喵
* @date 2019年9月18日下午3:53:51
*/
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入p1点的坐标");
int x1 = input.nextInt();
int y1 = input.nextInt();
System.out.println("请输入p2点的坐标");
int x2 = input.nextInt();
int y2 = input.nextInt(); MyPoint p1 = new MyPoint(x1, y1);
MyPoint p2 = new MyPoint(x2, y2);
System.out.println("两点之间的距离为;" + MyPoint.distance(p1, p2));
}
}
最新文章
- curl 小结
- log4net在Asp.net Mvc中的应用配置与介绍
- SQL Server 2005导入Excel表问题
- [转]java生成随机数字和字母组合
- Cocoa深入学习:NSOperationQueue、NSRunLoop和线程安全
- Apache配置rewrite
- hdu 3625 第一类striling 数
- Mysql找回管理员password
- SE 2014年4月13日
- JSTL 核心标签库 使用(转)
- 详细解剖大型H5单页面应用的核心技术点
- js 检测浏览器
- RPC服务不可用总结
- Spring Security(十四):5.4 Authorize Requests
- hdoj:2057
- [LeetCode] 422. Valid Word Square_Easy
- stm32f051 DMA需要注意的一点
- 【Python】将对象存成json文件及从json取出对象
- Redis查询&;JDBC查询&;Hibernate查询方式的效率比较...
- BurpSuite—-Repeater模块(中继器)