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

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

【零基礎(chǔ) 快速學(xué)Java】韓順平 零基礎(chǔ)30天學(xué)會Java

2023-02-12 22:39 作者:寒-梟  | 我要投稿

重點:++?%?/

arithmetic:算數(shù)

operator:運算符


public class ArithmeticOperotr

??public static void main.....


??System.out.println(10 / 4 );//從數(shù)學(xué)來看是2.5??但在java中是兩個整數(shù)進(jìn)行運算.所以最后的結(jié)果也是保留精度到整數(shù)--2

//注釋快捷鍵Ctrl+/


如果System.out.println(10.0 / 4);因為10.0是double所以精度提升.最后結(jié)果是2.5



?? double d = 10 / 4;最后結(jié)果是2.0因為計算時前面都是整數(shù).默認(rèn)算出來是就是2后面又因為都是雙精度就將結(jié)果變成了2.0(細(xì)節(jié))



//% 取模,取余數(shù)

System.out.println(10 % 3);//1

System.out.println(-10 % 3);//-1

System.out.println(10 % -3);//1(余數(shù)仍然是1)

System.our.println(-10 % -3);//-1



++ :自增

1.作為獨立語錄使用,

int i = 10;

i++;//自增?等價物 i=i+1;

++i;

System.out.println("i=" + i)//12

如果作為獨立語句使用前++和后++完全等價于i = i + 1;


2.作為表達(dá)式使用,

前++:++i先自增后賦值

后++:i++先賦值后自增


(前)int j = 8;

int k = ++j;//等價于j=j+1;k=j;

System.out.println("k=" + k + "j=" +j)//k=9.j=9


(后)int j = 8;

int k = j++;//此時會先把j的值賦給k,自己再增加

System.out.println("k=" + k + "j=" +j)//k=8.j=9

0113的練習(xí)

練習(xí):出票系統(tǒng)

4-10旺季:

成人(18-60):60

兒童(<18):半價

老人(>60):1/3


淡季:成人:40

其他:20


import java.util.Scanner;

public class Piaojia {

public static void main(String []args) {

Scanner myScanner = new Scanner (System.in);

System.out.println("請輸入當(dāng)前月份");

int month = myScanner.nextInt();

if(month >= 4 && month <= 10) {

System.out.println("當(dāng)前是旺季,請輸入你的年齡");

Scanner myScanner2 = new Scanner (System.in);

int years = myScanner2.nextInt();

if(years < 18) {

System.out.println("您是兒童,享受半價優(yōu)惠,需要支付30¥");

}

else if(years >= 18 && years < 60) {

System.out.println("您是成年人,需要支付60¥");

}

else if(years >= 60) {

System.out.println("您是老年人,享受1/3優(yōu)惠,需要支付20¥");

}

}

else{

System.out.println("當(dāng)前是淡季,請輸入你的年齡");

Scanner myScanner2 = new Scanner (System.in);

int years = myScanner2.nextInt();

if(years >= 18 && years < 60) {

System.out.println("您是成人,需要支付40¥");

}

else if(years < 18 || years >= 60) {

System.out.println("您可以享受優(yōu)惠,需要支付20¥");

}

}

}

}




0113的應(yīng)用練習(xí)

練習(xí):出票系統(tǒng)

4-10旺季:

成人(18-60):60

兒童(<18):半價

老人(>60):1/3


淡季:成人:40

??其他:20


import java.util.Scanner;

public class Piaojia {

public static void main(String []args) {

Scanner myScanner = new Scanner (System.in);

System.out.println("請輸入當(dāng)前月份");

int month = myScanner.nextInt();

if(month >= 4 && month <= 10) {

System.out.println("當(dāng)前是旺季,請輸入你的年齡");

Scanner myScanner2 = new Scanner (System.in);

int years = myScanner2.nextInt();

if(years < 18) {

System.out.println("您是兒童,享受半價優(yōu)惠,需要支付30¥");

}

else if(years >= 18 && years < 60) {

System.out.println("您是成年人,需要支付60¥");

}

else if(years >= 60) {

System.out.println("您是老年人,享受1/3優(yōu)惠,需要支付20¥");

}

}?

else{

System.out.println("當(dāng)前是淡季,請輸入你的年齡");

Scanner myScanner2 = new Scanner (System.in);

int years = myScanner2.nextInt();

??if(years >= 18 && years < 60) {

System.out.println("您是成人,需要支付40¥");

}

else if(years < 18 || years >= 60) {

System.out.println("您可以享受優(yōu)惠,需要支付20¥");

}

}

}

}

【零基礎(chǔ) 快速學(xué)Java】韓順平 零基礎(chǔ)30天學(xué)會Java的評論 (共 條)

分享到微博請遵守國家法律
新安县| 德州市| 宁河县| 吉首市| 安宁市| 大渡口区| 临澧县| 新巴尔虎左旗| 那坡县| 南城县| 邯郸市| 灌云县| 泸定县| 蛟河市| 梓潼县| 乌拉特中旗| 湘西| 宣汉县| 石台县| 大姚县| 丰城市| 开远市| 赞皇县| 道真| 桦甸市| 阿坝| 白水县| 库伦旗| 沂源县| 高青县| 康保县| 左贡县| 鲁甸县| 米泉市| 白银市| 夏津县| 清新县| 甘南县| 游戏| 海晏县| 余姚市|