国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

java方法的定義和調(diào)用

2022-06-07 10:41 作者:虛云幻仙  | 我要投稿

/**
* 測試方法的定義和調(diào)用
* 定義方法:修飾符(例如public/static)+返回值類型(例如int/double void為空不返回)+方法名+(形參){}
* 調(diào)用方法: 方法名+(實(shí)參);
*/

import java.util.Scanner;
public class TestMethod {
? ?public static void main(String[] args) {
? ? ? ?//main方法為程序的入口

? ? ? ?sayLoveYou();
? ? ? ?int sum = 0;
? ? ? ?add1(1,2,3);
? ? ? ?//實(shí)際調(diào)用輸入"add1(1,2,3);" a: b: c:為平臺提示
? ? ? ?System.out.println(sum);
? ? ? ?{
? ? ? ? ? ?//單獨(dú)的{}語句塊 可以使用外部的變量,語句塊內(nèi)的變量隨語句塊消失,外部不能使用語句塊內(nèi)的變量
? ? ? ? ? ?System.out.println(sum);
? ? ? ? ? ?int a1= 0;
? ? ? ?}
? ? ? ?int a1 = 0;

? ? ? ?Scanner s = new Scanner(System.in);
? ? ? ?System.out.println("輸入遲到時(shí)間(單位:分鐘):");
? ? ? ?int t = s.nextInt();
? ? ? ?System.out.println("輸入月薪");
? ? ? ?int m = s.nextInt();
? ? ? ?int money = handleLate(t,m);
? ? ? ?System.out.println("罰款金額:"+money);
? ?}

? ?public static void sayLoveYou(){

? ? ? ?System.out.println("I love you");
? ?}
? ?//定義方法sayLoveYou 無輸入和輸出 void是空、無返回return

? ?public static int add(int a,int b,int c){
? ? ? ?/*public static 修飾符
? ? ? ?int 返回值類型
? ? ? ?add方法名
? ? ? ?(int a,b,c)形參
? ? ? ? */

? ? ? ?return a+b+c;
? ? ? ?//執(zhí)行到return后結(jié)束方法運(yùn)行
? ?}

? ?public static int add1(int a,int b,int c){
? ? ? ?int sum = a+b+c;
? ? ? ?System.out.println("sum:"+sum);
? ? ? ?return sum;
? ? ? ?//方法內(nèi)定義的形參不影響方法外同樣名稱的變量
? ?}

? ?public static int handleLate(int lateTime, int monthSalary){
? ? ? ?int money = 0;
? ? ? ?if (lateTime<=0){
? ? ? ? ? ?System.out.println("沒有遲到");
? ? ? ?} else if (lateTime<=10) {
? ? ? ? ? ?System.out.println("警告一次");
? ? ? ?} else if (lateTime<=20) {
? ? ? ? ? ?System.out.println("罰款100元");
? ? ? ? ? ?money = 100;
? ? ? ?} else if (lateTime<=30) {
? ? ? ? ? ?System.out.println("罰款200元");
? ? ? ? ? ?money = 200;
? ? ? ?} else if (lateTime<=60) {
? ? ? ? ? ?System.out.println("罰款"+(monthSalary>>1)+"元");
? ? ? ? ? ?money = ?monthSalary/60;
? ? ? ?}else {
? ? ? ? ? ?System.out.println("曠工!罰款3日工資"+(monthSalary*3)+"元");
? ? ? ? ? ?money = monthSalary/10;
? ? ? ?}
? ? ? ?return money;
? ?}
}

java方法的定義和調(diào)用的評論 (共 條)

分享到微博請遵守國家法律
武功县| 阿坝| 永丰县| 康乐县| 钟祥市| 禄丰县| 灵宝市| 江山市| 社会| 会理县| 贵溪市| 潼南县| 安庆市| 丰宁| 永嘉县| 隆德县| 分宜县| 定西市| 即墨市| 大厂| 玛多县| 广德县| 张掖市| 齐齐哈尔市| 鲁甸县| 塔河县| 青川县| 沙雅县| 新巴尔虎左旗| 元江| 望江县| 大宁县| 启东市| 韶山市| 龙里县| 奇台县| 莫力| 二手房| 土默特右旗| 商城县| 通江县|