小奥的学习笔记

  • Home
  • Learning & Working
    • Speech Enhancement Notes
    • Programming language
    • Computer & DL
    • MOOC
  • Life
    • Life Time
    • Thinking & Comprehension
    • Volunteer
    • Plan
    • Travel
  • Footprints
  • GuestBook
  • About
    • About Me
    • 个人履历
    • 隐私策略
  1. 首页
  2. Study-notes
  3. Programming language
  4. Java
  5. 正文

Java语言程序设计【学堂在线】编程作业(第二章)

2018年3月8日 1434点热度 0人点赞 0条评论

创建一个简单的表示矩形的Rectangle类,满足以下条件:
1、定义两个成员变量height和width,表示矩形的长和宽,类型为整型 2、定义一个getArea方法,返回矩形的面积 3、定义一个getPerimeter方法,返回矩形的周长 4、在main函数中,利用输入的2个参数分别作为矩形的长和宽,调用getArea和getPermeter方法,计算并返回矩形的面积和周长
输入:
输入2个正整数,中间用空格隔开,分别作为矩形的长和宽,例如:5 8
输出:
输出2个正整数,中间用空格隔开,分别表示矩形的面积和周长,例如:40 26

正确答案:

import java.util.Scanner;
public class Main {
    static int height,weight;
    static int getArea(){        return height*weight;    }
    static int getPerimeter(){        return 2*(height+weight);    }
    public static void main(String[] args) {
   // write your code here
        Scanner input=new Scanner(System.in);
        height=input.nextInt();
        weight=input.nextInt();
        System.out.print(getArea());
        System.out.print(" ");
        System.out.print(getPerimeter());
    }
}

我的答案:

package homework;
import java.util.*;
public class Main {
//面积函数
static int getArea(int height, int weight) {
return height*weight;
}
//周长函数
static int getPerimeter(int height, int weight) {
return (height+weight)*2;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int height,weight;
System.out.println("Please input the height and weight");
Scanner input=new Scanner(System.in);
height = input.nextInt();
weight = input.nextInt();
System.out.print(getArea(height, weight));
System.out.print(" ");
System.out.print(getPerimeter(height, weight));
}
}

然而我并不知道我的答案错在了哪里,求解释。

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: Java
最后更新:2018年3月8日

davidcheung

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

搜索
欢迎关注我的个人公众号
最新 热点 随机
最新 热点 随机
DEEPFILTERNET:一种基于深度滤波的全频带音频低复杂度语音增强框架 奥地利匈牙利九日游旅程 论文阅读之Study of the General Kalman Filter for Echo Cancellation 小奥看房之鸿荣源珈誉府 杭州往返旅途及西溪喜来登和万怡的体验报告 2022年的第一篇碎碎念
奥地利匈牙利九日游旅程小奥看房之鸿荣源珈誉府论文阅读之Study of the General Kalman Filter for Echo CancellationDEEPFILTERNET:一种基于深度滤波的全频带音频低复杂度语音增强框架
《鸟哥的Linux私房菜》(基础篇)笔记整理(第5章) QQ好友再次更新 已修:模拟电子技术基础【清华大学】[2015-01-27] 《优化阵列信号处理》学习笔记(第三章) [Leetcode]merge sorted array 彻底弄懂CSS盒子模式
标签聚合
linux Java 算法 高中 鸟哥的linux私房菜 leetcode python学习 生活 学习 Python
最近评论
davidcheung 发布于 5 个月前(02月09日) The problem has been fixed. May I ask if you can s...
tk88 发布于 5 个月前(02月07日) Hmm is anyone else having problems with the pictur...
cuicui 发布于 8 个月前(10月20日) :wink:
niming 发布于 9 个月前(09月19日) 同级校友,能刷到太巧了
davidcheung 发布于 2 年前(08月16日) 我得找一下我之前整理的word文档看一下,如果找到了我就更新一下这篇文章。
Nolan 发布于 2 年前(07月25日) 您的笔记非常有帮助。贴图不显示了,可以更新一下吗?
davidcheung 发布于 3 年前(06月19日) 到没有看webrtc的代码。现在主要在看我们公司的代码了。。。只是偶尔看一看webrtc的东西。。。
aobai 发布于 3 年前(03月13日) gain_change_hangover_ 应该是每三个block 只能够调整一次,这样保证每帧...
匿名 发布于 5 年前(12月30日) 烫
小奥 发布于 5 年前(12月12日) webRTC里面的NS本身我记得就是在C++里面呀

COPYRIGHT © 2025 小奥的学习笔记. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

陕ICP备19003234号-1

鲁公网安备37120202000100号