Java面向对象4(P~U)
P 3-1 Point类的构造函数 (SDUT 2670)
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x,y;
x = sc.nextInt();
y = sc.nextInt();
System.out.println("(0,0)");
System.out.println("(" + x + "," + y + ")");
}
}
最佳拟合直线(SDUT 2728)
import java.util.Scanner;
public class Main {
static int n;
static double sum(double x[])
{
double s=0;
for(int i=0;i<n;i++)
s+=x[i];
return s;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double x[] = new double [20];
double y[] = new double [20];
double c[] = new double [20];
double d[] = new double [20];
double a1,b1,o;
n = in.nextInt();
for(int i = 0; i < n; i++){
x[i] = in.nextDouble();
y[i] = in.nextDouble();
c[i] = x[i] * y[i];
d[i] = x[i] * x[i];
}
a1 = n * sum(c) - sum(x) * sum(y);
b1 = sum(y) * sum(d) -sum(x) * sum(c);
o = n * sum(d) - Math.pow(sum(x), 2);
System.out.printf("%.3f\n",a1/o);
System.out.printf("%.3f\n",b1/o);
}
}
区域内点的个数(SDUT 2749)
//转载
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int count = sc.nextInt();
Point[] points = new Point[count];
int px1 = sc.nextInt();
int py1 = sc.nextInt();
int px2 = sc.nextInt();
int py2 = sc.nextInt();
Point p1 = new Point(px1, py1);
Point p2 = new Point(px2, py2);
int resultCount = 0;
for (int i = 0; i < count; i++) {
points[i] = new Point(sc.nextInt(), sc.nextInt());
if (points[i].inRect(p1, p2)) {
resultCount++;
}
}
System.out.println(resultCount);
}
sc.close();
}
}
class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public boolean inRect(Point p1, Point p2) {
boolean flag = false;
if (x > p1.x && x < p2.x && y > p1.y && y < p2.y) {
flag = true;
}
return flag;
}
}
谁是最强的女汉子(SDUT 3081)
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long []a = new long [11000];
long []b = new long [11000];
int n = sc.nextInt();
a[0] = sc.nextLong();
b[0] = sc.nextLong();
long min = a[0];
int c = 0;
long sum = 0;
for(int i = 1 ;i < n; i++) {
a[i] = sc.nextLong();
b[i] = sc.nextLong();
if(min > a[i]) {
min = a[i];
}
}
for(int i = 0 ;i < n ; i ++) {
if(min == a[i]) {
c++;
sum += b[i];
}
}
System.out.println(c+" "+sum);
}
}
飞花的糖果(SDUT 3268)
import java.util.Scanner;
class Candy{
int m, n;
public Candy(int n, int m) {
super();
this.m = m;
this.n = n;
}
public int count() {
int s1 =1;
int s2 =1;
for(int i=n; i>n-m; i--) {
s1 *= i;
}
for(int i=2; i<=m; i++) {
s2 *= i;
}
return s1/s2;
}
}
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
while(reader.hasNext()) {
int n = reader.nextInt();
int m = reader.nextInt();
Candy candy = new Candy(n, m);
System.out.println(candy.count());
}
}
}
计算长方体、四棱锥的表面积和体积(SDUT 3337)
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
while( in.hasNext() ){
double l = in.nextInt();
double h = in.nextInt();
double z = in.nextInt();
Cubic cub = new Cubic(l, h, z);
Pyramid py = new Pyramid(l, h, z);
DecimalFormat m = new DecimalFormat("0.00");
System.out.println(m.format(cub.area()) + " " + m.format(cub.volumn()) +" "
+ m.format(py.area()) + " " + m.format(py.volumn()) );
}
in.close();
}
}
class Rect {
double leng, high, zi;
public Rect(double l, double h, double z ){
if( l>0 && h>0 && z>0 ){
this.leng = l;
this.high = h;
this.zi = z;
}
}
public double length(){
return 2*(leng+high);
}
public double area(){
return leng*high;
}
}
class Cubic extends Rect{
public Cubic (double l, double h, double z ){
super(l, h, z);
}
public double area(){
return 2*super.area()+length()*zi;
}
public double volumn(){
return super.area()*zi;
}
}
class Pyramid extends Rect{
public Pyramid( double l, double h, double z ){
super(l, h, z);
}
public double area(){
return super.area() + leng*Math.sqrt(zi*zi+high*high/4) + high*Math.sqrt(zi*zi+leng*leng/4);
}
public double volumn(){
return super.area()*zi/3;
}
}
Java面向对象4(P~U)的更多相关文章
- JAVA面向对象
JAVA面向对象 对象 我们生活中能看到能摸到的一切事物都是对象.在程序中模拟出生活中的所有东西万物皆对象 只要是对象--属性和行为(方法) 属性 对象有什么 例如:学生有姓名.学 ...
- 理解JAVA - 面向对象(object) - 属性,方法
理解JAVA - 面向对象(object) - 属性,方法 多态的体现: 向上造型,父类接收子类对象:向上造型: 从父类角度看不到子类独有的方法:面向对象,人类认知世界的方式:生活中每天都 ...
- Java面向对象㈠ -- 封装
Java的面向对象有三大特征:封装.继承.多态.这里主要对封装进行讲解. 封装可以理解为隐藏一个类的成员变量和成员函数,只对外提供需要提供的成员函数. Java的封装主要通过访问权限控制符:priva ...
- 谈谈Java面向对象的三大特性
Java面向对象的三大特性就是指封装.继承.多态了. 一.封装: 概念:封装是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. (举例:笔记本电脑就是一个封装体,Java语言中最小的封装体就是函数 ...
- Java面向对象:接口
Java面向对象之接口 什么是接口:接口是一种规范和标准,他们可以约束类的行为,是一些方法特征的集合 语法: [修饰符] interface 接口名 extends 父接口1,夫接口2....... ...
- 实验二 Java面向对象程序设计
实验二 Java面向对象程序设计 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计 ...
- java基础1.0::Java面向对象、面向对象封装、抽象类、接口、static、final
一.前言 一直以来都是拿来主义,向大神学习,从网上找资料,现在就把自己在工作中和学习中的所理解的知识点写出来,好记星不如烂笔头,一来可以作为笔记自己温习,二来也可以给走在求学之路的同学们一点参考意见, ...
- 20145212《Java程序设计》实验报告二 《 Java面向对象程序设计》
20145212 实验二< Java面向对象程序设计> 实验内容 单元测试 三种代码 伪代码 百分制转五分制: 如果成绩小于60,转成"不及格" 如果成绩在60与70之 ...
- 20145213《Java程序设计》实验二Java面向对象程序设计实验报告
20145213<Java程序设计>实验二Java面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装,继承,多态 初步掌握UML建模 熟悉S.O. ...
- 20145206《Java程序设计》实验二Java面向对象程序设计实验报告
20145206<Java程序设计>实验二Java面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O. ...
随机推荐
- PyCryptodome安装使用方法
PyCryptodome是PyCrypto的一个分支.基于PyCrypto2.6.1,多了以下特性: Authenticated encryption modes (GCM, CCM, EAX, SI ...
- eclipse智能提示报错(to avoid the message, disable the...)
然后这里可能会再报别的错误 我的做法是 再重新将 code recommenders 打开 ********************************** 为什么会出现 这样错误呢 ? 简 ...
- LeetCode 754. Reach a Number
754. Reach a Number(到达终点数字) 链接:https://leetcode-cn.com/problems/reach-a-number/ 题目: 在一根无限长的数轴上,你站在0的 ...
- JS OOP -01 面向对象的基础
JS面向对象的基础: 1.用定义函数的方式定义类 2.用new操作符获得一个类的实例 3.使用 [ ] 引用对象的属性和方法 4.动态添加,修改,删除对象的属性和方法 5.使用 { } 语法创建无类型 ...
- JavaScript检测浏览器
Detect Browser <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- Android高版本收不到静态注册的广播
Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-de ...
- JavaScript流程图(精简版)
网址:https://www.processon.com/view/link/5db4f595e4b0c5553741c271 如果链接失效,请及时反馈(在评论区评论),博主会及时更新
- Android开发中UI相关的问题总结
UI设计和实现是Android开发中必不可少的部分,UI做不好的话,丑到爆,APP性能再好,估计也不会有多少人用吧,而且如果UI和业务代码逻辑中间没有处理好,也会很影响APP的性能的.稍微总结一下,开 ...
- linux命令安装docker
安装: 1.Docker要求CentOS系统的内核版本高于 3.10 ,通过 uname -r 命令查看你当前的内核版本是否支持安账docker 2.更新yum包:sudo yum update 3. ...
- JavaScript(js)概述
一.特点: JavaScript和java并没有直接关系,就像雷锋与雷峰塔似的没有联系: js是面向对象的,是运行在浏览器端的编程语言: 主要解决的是前端与用户的交互问题,包括交互数据. 二.js引入 ...