最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

Java oop代碼5(原創(chuàng)方法):添加非靜態(tài)的方法,買手機(jī)時(shí),設(shè)置手機(jī)名稱

2019-12-16 23:33 作者:詩書畫唱  | 我要投稿

//創(chuàng)建一個(gè)Human類

//添加一個(gè)非靜態(tài)屬性String mobile(手機(jī)),添加非靜態(tài)的方法:買手機(jī)時(shí),設(shè)置手機(jī)名稱

//丟手機(jī)時(shí),手機(jī)名稱設(shè)置為null

//添加一個(gè)靜態(tài)屬性long count(世界人口總數(shù)) =?

//1500000000;添加靜態(tài)方法:出生(人口數(shù)+1),死亡(人口數(shù)-1)。在main方法中調(diào)用。


package a;


import java.util.*;


public class Human {// public可不寫,不寫就有默認(rèn)的修飾訪問符

private String mobile;// 用private會(huì)更安全,但要用上getXXX() setxxx()

private static long count = 1500000000;


public String getMobile() {

return mobile;

}


public void setMobile(String mobile) {

this.mobile = mobile;

}


public static long getCount() {

return count;

}


public static void setCount(long count) {

Human.count = count;

}


public void info() { // 定義一個(gè)方法


Scanner sstring = new Scanner(System.in);

Scanner sint = new Scanner(System.in);

System.out.println("請(qǐng)輸入你的操作:1.買手機(jī)? 2.丟手機(jī)");


int num = sint.nextInt();


if (num == 1) {


System.out.println("請(qǐng)輸入手機(jī)名稱");


String uname = sstring.next();

System.out.println("買手機(jī),手機(jī)名稱為" + uname);

} else if (num == 2) {

mobile = null;

System.out.println("丟手機(jī)時(shí),手機(jī)名稱設(shè)置為:" + mobile);


} else {


System.out.println("輸入錯(cuò)誤");


}

}






public static void me() {

count = count + 1;

System.out.println("出生(人口數(shù)+1):" + count);

count = count - 1;

System.out.println("死亡(人口數(shù)-1):" + count);


}


public static void main(String[] args) {



Human a = new Human();

a.info();


Human.me();


}


}



Java oop代碼5(原創(chuàng)方法):添加非靜態(tài)的方法,買手機(jī)時(shí),設(shè)置手機(jī)名稱的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
桦甸市| 黎城县| 托克逊县| 久治县| 芜湖县| 和静县| 拉孜县| 肥城市| 缙云县| 平武县| 措勤县| 且末县| 盐池县| 花垣县| 三穗县| 邛崃市| 灵川县| 洪江市| 乐东| 石嘴山市| 邹平县| 霍邱县| 固镇县| 信宜市| 惠东县| 昆明市| 四川省| 余庆县| 嵊州市| 镇巴县| 永吉县| 遂川县| 集安市| 项城市| 蕉岭县| 耿马| 陆河县| 乐业县| 阳西县| 陈巴尔虎旗| 额尔古纳市|