博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
无参有返回值方法-求长方形面积
阅读量:7221 次
发布时间:2019-06-29

本文共 845 字,大约阅读时间需要 2 分钟。

package com.imooc.method;public class Rectangle {	//求长方形面积的方法	public int area(){		int length=10;		int width=5;		int getArea=length*width;		return getArea;//返回语句	}	public static void main(String[] args) {		Rectangle rc=new Rectangle();		System.out.println("长方形的面积为:"+rc.area());	}}

 

 

升级版

package com.imooc.method;import java.util.Scanner;public class Rectangle {	// 求长方形面积的方法	public int area() {		System.out.println("请输入长方形的长:");		Scanner sc1 = new Scanner(System.in);		int length = sc1.nextInt();		System.out.println("请输入长方形的宽:");		Scanner sc2 = new Scanner(System.in);		int width = sc2.nextInt();		int getArea = length * width;		return getArea;// 返回语句	}	public static void main(String[] args) {		Rectangle rc = new Rectangle();		System.out.println("长方形的面积为:" + rc.area());	}}

  

 长方形的面积为:50

转载于:https://www.cnblogs.com/hanzhenhua/p/8196198.html

你可能感兴趣的文章
9 Web开发——springmvc自动配置原理
查看>>
截取图片
查看>>
Python学习--01入门
查看>>
MySQL联合查询语法内联、左联、右联、全联
查看>>
看牛顿法的改进与验证局部收敛
查看>>
第十篇、自定义UIBarButtonItem和UIButton block回调
查看>>
复分析学习1
查看>>
Java虚拟机笔记(四):垃圾收集器
查看>>
计算机运行命令全集
查看>>
WebSocket 实战
查看>>
二次排序
查看>>
CSS:如何清除a标签之间的默认留白间距
查看>>
selenium随笔
查看>>
leetcode599
查看>>
String类中“==”和“equals()”的区别
查看>>
leetcode--883
查看>>
the application could not be verified
查看>>
[转]Centos配置国内yum源
查看>>
redis数据类型和应用场景
查看>>
Spring IOC
查看>>