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. ...
随机推荐
- Luogu4081 USACO17DEC Standing Out from the Herd(广义后缀自动机)
建出广义SAM,通过parent树对每个节点求出其是否仅被一个子串包含及被哪个包含. 写了无数个sam板子题一点意思都没啊 #include<bits/stdc++.h> using na ...
- (二) JPA基础
一.什么是JAP JPA(Java Persistence API)是SUN官方推出的Java持久化规范,它为Java开发人员提供了一种对象/关联映射工具来管理Java应用中的关系数据.它的出现主要是 ...
- LeetCode 754. Reach a Number
754. Reach a Number(到达终点数字) 链接:https://leetcode-cn.com/problems/reach-a-number/ 题目: 在一根无限长的数轴上,你站在0的 ...
- 数据仓库之抽取数据:通过bcp命令行导入数据
原文:数据仓库之抽取数据:通过bcp命令行导入数据 在做数据仓库时,最重要的就是ETL的开发,而在ETL开发中的第一步,就是要从原OLTP系统中抽取数据到过渡区中,再对这个过渡区中的数据进行转换,最后 ...
- Bat 批处理启动和停止Oracle 服务
实际情况 * 不想开机自启动oracle服务,因为Windows 没有固态硬盘本身启动就很慢了,然后也不想自己手动的方式去启东oracle 服务 解决方案 *1启动 ``` @echo off ech ...
- spring cloud Eureka 配置信息
Eureka instance 一个服务,如:订单系统,会部署多台服务器,而每台服务器上提供的服务就是instance; 负载配置. Eureka service 指的是服务,提供一种特定功能的服务, ...
- Python练习_数据类型_day5
1. 1.作业 1,有如下变量(tu是个元祖),请实现要求的功能 tu = ("alex", [11, 22, {"k1": 'v1', "k2&qu ...
- mac使用sourcetree跳过注册
转自https://blog.csdn.net/qq_32890891/article/details/89216954 打开sourcetree 关闭sourcetree 命令终端输入default ...
- alibaba 用360的evpp -》个别项目
- day 02(作业)
作业 1.什么是编程 编程即编写程序,基于某种语法格式将想要实现的事情写出可以让计算机能够理解的文件,文件的集合即为程序.目的是使计算机操作更简单及大众化,提高工作效率. 2.简述计算机五大组成. 控 ...