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

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

黑馬程序員Java入門視頻速成篇(適合有java基礎(chǔ)、想二刷Java基礎(chǔ)的同學(xué),

2023-03-21 01:53 作者:聽雨競技  | 我要投稿

# 概述


? ? # JavaSE ? 應(yīng)用開發(fā)

? ? # JavaEE ? 服務(wù)器開發(fā)


? ? # 編譯:javac main.java

? ? # 編譯指定編碼:javac -encoding utf-8 main.java

? ? # 運(yùn)行:java main


# 基本結(jié)構(gòu)


? ? # # 類

? ? # class init_main{

? ? # ? ? # 主函數(shù) , 初始化函數(shù)

? ? # ? ? public static void main(String[] args){

? ? # ? ? ? ? # 調(diào)用 System 類中的 out 類中的 println 函數(shù)

? ? # ? ? ? ? System.out.println("hello world");

? ? # ? ? }

? ? # }


# 輸入輸出


? ? # 標(biāo)準(zhǔn)輸入


? ? ? ? # 例1:手動關(guān)閉資源


? ? ? ? ? ? # import java.util.Scanner;


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args){

? ? ? ? ? ? # ? ? ? ? Scanner sc = ?new Scanner(System.in);

? ? ? ? ? ? # ? ? ? ? int p = sc.nextInt();

? ? ? ? ? ? # ? ? ? ? System.out.println(p);

? ? ? ? ? ? # ? ? ? ? sc.close();

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? ? ? # 例2:自動關(guān)閉資源


? ? ? ? ? ? # import java.util.Scanner;


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args){

? ? ? ? ? ? # ? ? ? ? try (Scanner sc = new Scanner(System.in)) {

? ? ? ? ? ? # ? ? ? ? ? ? int p = sc.nextInt();

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println(p);

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? # 標(biāo)準(zhǔn)輸出


? ? ? ? # class init_main{

? ? ? ? # ? ? public static void main(String[] args){

? ? ? ? # ? ? ? ? System.out.println("你好,世界!");

? ? ? ? # ? ? }

? ? ? ? # }


# 數(shù)據(jù)類型


? ? # 精度:double > float > long > int > short > byte


? ? # 整型 ?int ? ? -2147483648 ———— 2147483647 ?(10位數(shù))


? ? ? ? # int i = 40;


? ? # 整型 ?long ? ?-9223372036854775808 ———— 9223372036854775807 ?(19位數(shù))


? ? ? ? # long l = 30L;


? ? # 整型 ?short ? -32768 ———— 32767


? ? ? ? # short s = 20;


? ? # 浮點(diǎn)數(shù) float ?-3.401298e-38 ———— 3.402823e+38


? ? ? ? # float f = 3.1415926F;


? ? # 浮點(diǎn)數(shù) double ?-4.9000000e-324 ———— 1.797693e+308


? ? ? ? # double d = 20.2;


? ? # 字符 ?char ? ?0 ———— 65535


? ? ? ? # char c = '中';


? ? # 字節(jié) ?byte ? ?-128 ———— 127


? ? ? ? # byte b = 10;


? ? # 字符串 ?String


? ? ? ? # String name = "tony";


? ? # 布爾 boolean ? true or false


? ? ? ? # boolean o = true;


# 條件語句


? ? # if 分支


? ? ? ? # 例1


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? int a = 10;

? ? ? ? ? ? # ? ? ? ? int b = 120;

? ? ? ? ? ? # ? ? ? ? int c = 100;

? ? ? ? ? ? # ? ? ? ? if (a + b > c){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("分支1, a和b的和為:" + (a + b));

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? else{

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("分支2, a和b的和為:" + (a + b));

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? ? ? # 例2


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? int a = 10;

? ? ? ? ? ? # ? ? ? ? int b = 10;

? ? ? ? ? ? # ? ? ? ? int c = 100;

? ? ? ? ? ? # ? ? ? ? if (!(a + b > c)){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("分支2, a和b的和為:" + (a + b));

? ? ? ? ? ? # ? ? ? ? ? ? return;

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? System.out.println("分支1, a和b的和為:" + (a + b));

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? ? ? # 例3


? ? ? ? ? ? # import java.util.Scanner;


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? System.out.println("小明的成績?yōu)椋?#34;);

? ? ? ? ? ? # ? ? ? ? Scanner sc = ?new Scanner(System.in);

? ? ? ? ? ? # ? ? ? ? int i = sc.nextInt();

? ? ? ? ? ? # ? ? ? ? if (i >=0 && i <= 100){

? ? ? ? ? ? # ? ? ? ? ? ? if (i >= 95){

? ? ? ? ? ? # ? ? ? ? ? ? ? ? System.out.println("獎勵手機(jī)一部");

? ? ? ? ? ? # ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? ? ? else if (i >= 90){

? ? ? ? ? ? # ? ? ? ? ? ? ? ? System.out.println("游樂場玩一天");

? ? ? ? ? ? # ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? ? ? else if (i >= 85){

? ? ? ? ? ? # ? ? ? ? ? ? ? ? System.out.println("100元現(xiàn)金");

? ? ? ? ? ? # ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? ? ? else{

? ? ? ? ? ? # ? ? ? ? ? ? ? ? System.out.println("打一頓");

? ? ? ? ? ? # ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? }else{

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("錄入的成績不合法");

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? sc.close();

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? # switch 分支


? ? ? ? # 例1


? ? ? ? ? ? # import java.util.Scanner;


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? Scanner sc = new Scanner(System.in);

? ? ? ? ? ? # ? ? ? ? boolean state = true;

? ? ? ? ? ? # ? ? ? ? while (state){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("選擇分支任務(wù):");

? ? ? ? ? ? # ? ? ? ? ? ? int i = sc.nextInt();

? ? ? ? ? ? # ? ? ? ? ? ? state = taskAllocation(i);

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? sc.close();

? ? ? ? ? ? # ? ? }


? ? ? ? ? ? # ? ? static boolean taskAllocation(int value){

? ? ? ? ? ? # ? ? ? ? switch(value){

? ? ? ? ? ? # ? ? ? ? ? ? case 1:

? ? ? ? ? ? # ? ? ? ? ? ? ? ? t1();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return true;

? ? ? ? ? ? # ? ? ? ? ? ? case 2:

? ? ? ? ? ? # ? ? ? ? ? ? ? ? t2();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return true;

? ? ? ? ? ? # ? ? ? ? ? ? case 3:

? ? ? ? ? ? # ? ? ? ? ? ? ? ? t3();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return true;

? ? ? ? ? ? # ? ? ? ? ? ? case 4:

? ? ? ? ? ? # ? ? ? ? ? ? ? ? t4();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return true;

? ? ? ? ? ? # ? ? ? ? ? ? default:

? ? ? ? ? ? # ? ? ? ? ? ? ? ? System.out.println("輸入錯誤");

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return false;

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }


? ? ? ? ? ? # ? ? static void t1(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t1");

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? ? ?

? ? ? ? ? ? # ? ? static void t2(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t2");

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? ? ?

? ? ? ? ? ? # ? ? static void t3(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t3");

? ? ? ? ? ? # ? ? }


? ? ? ? ? ? # ? ? static void t4(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t4");

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? ? ? # 例2


? ? ? ? ? ? # import java.util.Scanner;


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? Scanner sc = new Scanner(System.in);

? ? ? ? ? ? # ? ? ? ? boolean state = true;

? ? ? ? ? ? # ? ? ? ? while (state){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("選擇分支任務(wù):");

? ? ? ? ? ? # ? ? ? ? ? ? int i = sc.nextInt();

? ? ? ? ? ? # ? ? ? ? ? ? state = taskAllocation(i);

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? sc.close();

? ? ? ? ? ? # ? ? }


? ? ? ? ? ? # ? ? static boolean taskAllocation(int value){

? ? ? ? ? ? # ? ? ? ? switch(value){

? ? ? ? ? ? # ? ? ? ? ? ? case 1,2,3,4 :

? ? ? ? ? ? # ? ? ? ? ? ? ? ? switch (value) {

? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? case 1 -> t1();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? case 2 -> t2();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? case 3 -> t3();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? case 4 -> t4();

? ? ? ? ? ? # ? ? ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return true;

? ? ? ? ? ? # ? ? ? ? ? ? default:

? ? ? ? ? ? # ? ? ? ? ? ? ? ? System.out.println("輸入錯誤");

? ? ? ? ? ? # ? ? ? ? ? ? ? ? return false;

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }


? ? ? ? ? ? # ? ? static void t1(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t1");

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? ? ?

? ? ? ? ? ? # ? ? static void t2(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t2");

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? ? ?

? ? ? ? ? ? # ? ? static void t3(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t3");

? ? ? ? ? ? # ? ? }


? ? ? ? ? ? # ? ? static void t4(){

? ? ? ? ? ? # ? ? ? ? System.out.println("執(zhí)行任務(wù) t4");

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? # 與 (&&)


? ? ? ? # class init_main{

? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? # ? ? ? ? int a = 10;

? ? ? ? # ? ? ? ? int b = 120;

? ? ? ? # ? ? ? ? int c = 100;

? ? ? ? # ? ? ? ? int d = 200;

? ? ? ? # ? ? ? ? if (a + b > c && a + b < d){

? ? ? ? # ? ? ? ? ? ? System.out.println("分支1, a和b的和為:" + (a + b));

? ? ? ? # ? ? ? ? }

? ? ? ? # ? ? ? ? else{

? ? ? ? # ? ? ? ? ? ? System.out.println("分支2, a和b的和為:" + (a + b));

? ? ? ? # ? ? ? ? }

? ? ? ? # ? ? }

? ? ? ? # }


? ? # 或 (||)


? ? ? ? # class init_main{

? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? # ? ? ? ? int a = 10;

? ? ? ? # ? ? ? ? int b = 500;

? ? ? ? # ? ? ? ? int c = 100;

? ? ? ? # ? ? ? ? int d = 200;

? ? ? ? # ? ? ? ? if (a + b < c || a + b < d){

? ? ? ? # ? ? ? ? ? ? System.out.println("分支1, a和b的和為:" + (a + b));

? ? ? ? # ? ? ? ? }

? ? ? ? # ? ? ? ? else{

? ? ? ? # ? ? ? ? ? ? System.out.println("分支2, a和b的和為:" + (a + b));

? ? ? ? # ? ? ? ? }

? ? ? ? # ? ? }

? ? ? ? # }


? ? # 非 (!)


? ? ? ? # class init_main{

? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? # ? ? ? ? boolean bool = false;

? ? ? ? # ? ? ? ? if (! bool){

? ? ? ? # ? ? ? ? ? ? System.out.println("分支1");

? ? ? ? # ? ? ? ? }

? ? ? ? # ? ? ? ? else{

? ? ? ? # ? ? ? ? ? ? System.out.println("分支2");

? ? ? ? # ? ? ? ? }

? ? ? ? # ? ? }

? ? ? ? # }


# 循環(huán)

? ? # while 循環(huán)


? ? ? ? # 例1


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? boolean state = true;

? ? ? ? ? ? # ? ? ? ? int n = 0;

? ? ? ? ? ? # ? ? ? ? while (state){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println(n);

? ? ? ? ? ? # ? ? ? ? ? ? n = n + 1;

? ? ? ? ? ? # ? ? ? ? ? ? if (n == 10){

? ? ? ? ? ? # ? ? ? ? ? ? ? ? state = false;

? ? ? ? ? ? # ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? ? ? # 例2


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? boolean state = true;

? ? ? ? ? ? # ? ? ? ? int n = 0;

? ? ? ? ? ? # ? ? ? ? while (state){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println(n);

? ? ? ? ? ? # ? ? ? ? ? ? n = n + 1;

? ? ? ? ? ? # ? ? ? ? ? ? if (n == 10){

? ? ? ? ? ? # ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? # ? ? ? ? ? ? }

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? # for 循環(huán)


? ? ? ? # 無限循環(huán)


? ? ? ? ? ? # class init_main{

? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? # ? ? ? ? for (;;){

? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("你好");

? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? # ? ? }

? ? ? ? ? ? # }


? ? ? ? # 有限循環(huán)


? ? ? ? ? ? # 例1


? ? ? ? ? ? ? ? # class init_main{

? ? ? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? ? ? # ? ? ? ?# 參數(shù)1為初始化變量 , 參數(shù)2為循環(huán)條件 , 條件不成立則終止循環(huán) , 參數(shù)3為更新條件

? ? ? ? ? ? ? ? # ? ? ? ? for (int i = 0; i != 10; i = i + 1){

? ? ? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("你好");

? ? ? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? ? ? # ? ? }

? ? ? ? ? ? ? ? # }


? ? ? ? ? ? # 例2


? ? ? ? ? ? ? ? # class init_main{

? ? ? ? ? ? ? ? # ? ? public static void main(String[] args) {

? ? ? ? ? ? ? ? # ? ? ? ? for (int i = 0; i != 10;){

? ? ? ? ? ? ? ? # ? ? ? ? ? ? System.out.println("你好");

? ? ? ? ? ? ? ? # ? ? ? ? ? ? i = i + 1;

? ? ? ? ? ? ? ? # ? ? ? ? }

? ? ? ? ? ? ? ? # ? ? }

? ? ? ? ? ? ? ? # }


# 函數(shù)


? ? # class init_main{

? ? # ? ? public static void main(String[] args) {

? ? # ? ? ? ? int sun = add(100,200);

? ? # ? ? ? ? System.out.println(sun);


? ? # ? ? ? ? System.out.println(add(100,200));

? ? # ? ? }

? ? ? ?

? ? # ? ? static int add(int a,int b){

? ? # ? ? ? ? return a + b;

? ? # ? ? }

? ? # }


黑馬程序員Java入門視頻速成篇(適合有java基礎(chǔ)、想二刷Java基礎(chǔ)的同學(xué),的評論 (共 條)

分享到微博請遵守國家法律
昌黎县| 永靖县| 建始县| 遵化市| 治多县| 九台市| 石狮市| 彭泽县| 进贤县| 扎赉特旗| 孟村| 微山县| 界首市| 措美县| 锦屏县| 木里| 开平市| 阿拉善右旗| 巴南区| 辽宁省| 达拉特旗| 忻州市| 景谷| 台州市| 南宫市| 洱源县| 陆河县| 伊通| 长丰县| 武宣县| 黄大仙区| 太白县| 铜陵市| 苗栗市| 自治县| 北海市| 汉川市| 华亭县| 太和县| 札达县| 会泽县|