计算长方形的周长和面积(类和对象java)
计算长方形的周长和面积(类和对象)
Problem Description
Input
Output
Example Input
1 2 3 4 5 2 -2 -2 -3
Example Output
1 1 4 1 2 3 10 6 4 5 18 20 2 2 8 4 0 0 0 0 0 0 0 0
Hint
import java.util.*;
import java.lang.*;public class Main {private static Scanner in;public static void main(String[] args) {in = new Scanner(System.in);while(true){String s = in.nextLine();String[] a = s.split(" ");int b[] = new int [2];for(int i=0; i<a.length; ++i){b[i] = Integer.parseInt(a[i]);}if(a.length == 1){Rect R1 = new Rect(b[0]);System.out.println(R1.getlength() + " " + R1.getwidth() + " " + R1.sslen() + " " + R1.sarea());}else{Rect R2 = new Rect(b[0], b[1]);System.out.println(R2.getlength() + " " + R2.getwidth() + " " + R2.sslen() + " " + R2.sarea());}}}
}class Rect{private int length, width;public Rect(int length){if(length < 0)this.length = 0;elsethis.length = length;this.width = this.length;}public Rect(int length, int width){if(length < 0 || width < 0){this.length = 0;this.width = 0;return;}this.length = length;this.width = width;}public int sarea(){if(width == 0)return length * length;return width * length;}public int sslen(){if(width == 0)return 4 * length;return 2 * (length + width);}public int getlength(){return length;}public int getwidth(){return width;}
}
计算长方形的周长和面积(类和对象java)相关推荐
- java长方形周长计算_Java练习 SDUT-3339_计算长方形的周长和面积(类和对象)
###计算长方形的周长和面积(类和对象) Time Limit: 1000 ms Memory Limit: 65536 KiB ####Problem Description 设计一个长方形类Rec ...
- 计算长方形的周长和面积(类和对象)_JAVA
Description 设计一个长方形类Rect,计算长方形的周长与面积. 成员变量:整型.私有的数据成员length(长).width(宽): 构造方法如下: (1)Rect(int length) ...
- 声明一个长方形类,属性有长和宽;操作有赋值、计算长方形的周长和面积、输出信息等,要求定义构造函数(缺省值为10)和析构函数。
题目描述:声明一个长方形类,属性有长和宽:操作有赋值.计算长方形的周长和面积.输出信息等,要求定义构造函数(缺省值为10)和析构函数. 析构函数的作用:对象消亡时,自动被调用,用来释放对象占用的空间. ...
- java定义一个长方形类,该类中具有长方形长宽两种属性,并具有相应的构造方法属性访问方法,计算长方形的周长和面积的方法,要求输出长是5,宽是4的长方形
定义一个长方形类,该类中具有长方形长宽两种属性,并具有相应的构造方法 属性访问方法,计算长方形的周长和面积的方法,要求输出长是5,宽是4的长方形 public class test3 {public ...
- 计算长方形的周长和面积(类和对象)
计算长方形的周长和面积(类和对象) Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 设计一个长方形类Rect,计算长方形 ...
- 计算长方形的周长和面积(类和对象)(SDUT 3339)
说明:主要是练习类和对象的定义,用于笔试. 计算长方形的周长和面积(类和对象) Problem Description 设计一个长方形类Rect,计算长方形的周长与面积. 成员变量:整型.私有的数据成 ...
- 计算长方形的周长和面积(类和对象)python
计算长方形的周长和面积(类和对象) 设计一个长方形类Rect,计算长方形的周长与面积.成员变量:整型.私有的数据成员length(长).width(宽): 构造方法如下: (1)Rect(int le ...
- Java—计算长方形的周长和面积(类和对象)
Java-计算长方形的周长和面积(类和对象) Description 设计一个长方形类Rect,计算长方形的周长与面积. 成员变量:整型.私有的数据成员length(长).width(宽): 构造方法 ...
- 7-4 sdut-oop-9 计算长方形的周长和面积(类和对象) (10 分)
设计一个长方形类Rect,计算长方形的周长与面积. 成员变量:整型.私有的数据成员length(长).width(宽): 构造方法如下: (1)Rect(int length) -- 1个整数表示正方 ...
最新文章
- SAP MM 公司间STO里交货单PGI之后自动触发内向交货单功能的实现
- UGUI的优点新UI系统三效率高效果好
- 使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失
- 10-动态SQL语句
- javascript基础语法——词法结构
- s5pv210 uboot-2012-10移植(七) 之支持SD卡
- Git常用操作命令----有备无患
- 练习五十一:序列交换
- 数据加密技术之加密算法
- ENVI大气校正后遥感图像颜色变了及编辑头文件
- supervise用法_supervise过去式和用法例句
- jinjia2调用json文件注意事项
- Jsonp解决跨域问题原理
- webp是什么文件格式?
- 不满足作对(JZ2 替换空格(Java))
- 两款程序员的好帮手——BitNami,Hoo WinTail
- usr目录linux,linux之usr目录的概述
- mybatis-generator工具生成对应的自定Service和Controller
- 转行学java被辞退_不是所有行业都是“跳槽穷半年,转行穷三年”,至少转行学Java不是!...
- iOS Touch ID 简易开发教程