Java學習第一天

來源:互聯網
上載者:User

標籤:之間   重複   case   family   span   單行   商務邏輯   比較   lips   

JDK的安裝與配置 :

下載:

安裝:傻瓜式(注意:不要裝在C盤)

配置:

1, JAVA_HOME

2, classpath

3, path

驗證:

1, javac

2, java -version

 

安裝myeclipse/eclipse

開啟:

建立項目

最左側空白--右鍵—new java project—project name—(注意)—finish

注意:(Java標識符的命名規範)

1, 由字母,數字,底線(_),貨幣符號($)組成,數字不能開頭

2, 不能是Java中的關鍵字或保留字(const,goto)

3,駝峰式命名,大小寫區分,沒有長度限制,見名知意

 

int      age      =     18;

//資料類型    變數名     賦值號 變數值

 

Java中的資料類型:

基礎資料型別 (Elementary Data Type):四類八種

整形:byte(1),short(2),int(4),long(8)

浮點:float(4),double(8)

字元:char

布爾:boolean(true/false)

引用資料類型:

自轉:資料類型範圍由小到大

強轉:資料類型範圍由大到小

 

注釋:

單行注釋://

多行注釋:/*    */

文檔注釋:/**   * /

 

流程式控制制語句:if  else   switch case  ,  for ,while,do while

語句結構,運算式

 

 

迴圈:

什麼時候用迴圈:大量重複商務邏輯的時候

While與do while的區別:

 

 

 

 

 

 

 

 

 

 

 

 

JDK的安裝與配置 :

下載:

安裝:傻瓜式(注意:不要裝在C盤)

配置:

1, JAVA_HOME

2, classpath

3, path

驗證:

1, javac

2, java -version

 

安裝myeclipse/eclipse

開啟:

建立項目

最左側空白--右鍵—new java project—project name—(注意)—finish

注意:(Java標識符的命名規範)

1, 由字母,數字,底線(_),貨幣符號($)組成,數字不能開頭

2, 不能是Java中的關鍵字或保留字(const,goto)

3,駝峰式命名,大小寫區分,沒有長度限制,見名知意

 

int      age      =     18;

//資料類型    變數名     賦值號 變數值

 

Java中的資料類型:

基礎資料型別 (Elementary Data Type):四類八種

整形:byte(1),short(2),int(4),long(8)

浮點:float(4),double(8)

字元:char

布爾:boolean(true/false)

引用資料類型:

自轉:資料類型範圍由小到大

強轉:資料類型範圍由大到小

 

注釋:

單行注釋://

多行注釋:/*    */

文檔注釋:/**   * /

 

流程式控制制語句:if  else   switch case  ,  for ,while,do while

語句結構,運算式

 

 

迴圈:

什麼時候用迴圈:大量重複商務邏輯的時候

While與do while的區別:

 

 

import java.util.Scanner;

 

public class Demo {
public static void main(String[] args) {
//運算式
/* 題意:溫度高於35度,去遊泳。否則,在家睡覺
* 思路:
* 1,建立溫度變數 int tem = 28;
* 2,比較溫度
* tem>35 結果:去遊泳
* tem<=35 結果:睡覺
*
* 練習:
* 假如我的工資3000以下,買小米手機
* 4000以下,買諾基亞
* 5000以下,HTC
* 6000以下,蘋果
*
* */
//int salary = 3800;
//if(salary<3000){
//System.out.println("買小米");
//}else if(salary<4000){
//System.out.println("買諾基亞");
//}else if(salary<5000){
//System.out.println("HTC");
//}else if(salary<6000){
//System.out.println("買蘋果");
//}

//switch case

//Scanner aa = new Scanner(System.in);
//System.out.println("請輸入資料");
//int day = aa.nextInt();
//switch (day) {
//case 1:
//System.out.println("周一");
//break;
//case 2:
//System.out.println("周二");
//break;
//case 3:
//System.out.println("周三");
//break;
//case 4:
//System.out.println("周四");
//break;
//case 5:
//System.out.println("周五");
//break;
//case 6:
//System.out.println("周六");
//break;
//case 7:
//System.out.println("周日");
//break;
//default:
//System.out.println("對不起,您該回火星了,地球上一周只有7天");
//}
/**
* 考試時,90--100分,優秀,80--89,良好,70--79,一般,60--69,及格,60以下,不及格
* */

//Scanner input = new Scanner(System.in);
//System.out.println("請輸入您的分數:");
//int score = input.nextInt();
//if(score<0 || score>100){
//System.out.println("輸入有誤");
//}else{
//switch (score/10) {
//case 0:
//case 1:
//case 2:
//case 3:
//case 4:
//case 5:
//System.out.println("不及格");
//break;
//case 6:
//System.out.println("及格");
//break;
//case 7:
//System.out.println("一般");
//break;
//case 8:
//System.out.println("良好");
//break;
//case 9:
//case 10:
//System.out.println("優秀");
//}
//}
// 124
//for (int i = 0; i < 5000; i++) {
////3
//System.out.println("第"+(i+1)+"遍:小紅,我愛你");
//}


//int a = 0;
//while (a>5000) {
//System.out.println("第"+a+"遍:小紅,我愛你");
//a++;
//}

//int a = 0;
//do{
//System.out.println("第"+(a+1)+"遍:小紅,我愛你");
//a++;
//}while(a>5000);


/*
* 求1--100之間的偶數和,偶數個數
* */
//int sum =0;
//int count=0;
//for (int i = 1; i <= 100; i++) {
//if(i % 2 == 0){
//sum= sum+i;
//count++;
//}
//}
//System.out.println("1--100之間的和是:"+sum);
//System.out.println("偶數個數是:"+count);

//什麼情況用if else ?什麼情況用switch case?

//Scanner sc = new Scanner(System.in);
//System.out.println("請輸入資料:");
//String name = sc.next();
//char c = ‘r‘;
//long b = 3;
//switch (b) {
//case 1:
//System.out.println("您輸入的是true");
//break;
//case 3:
//System.out.println("您輸入的是false");
//default:
//break;
//}

//for (int i = 1; i <= 9 ; i++) {
//for (int j = 1; j <= i; j++) {
//System.out.print(j+"*"+i+"="+i*j+" ");
//}
//System.out.println();
//}

//for (int i = 1; i <= 9; i++) {//行
//for (int j = 1; j <= i; j++) {//列
//System.out.print(j+"*"+i+"="+i*j+" ");
//}
//System.out.println();
//}

/**
* 百元買百隻雞,公雞:5元一隻,母雞:3元一隻,小雞:1元3隻,要求,公雞,母雞,小雞都必須有,問:能買幾隻公雞,幾隻母雞,幾隻小雞?
* */








}
}

 

Java學習第一天

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.