發表文章

目前顯示的是有「JAVA學習」標籤的文章

JAVA程式語法_物件導向Part2_static關鍵字使用之便利_final關鍵字使用

圖片
static關鍵字使用之便利 各位還記得之前分享了 JAVA OOP 我們拿了  車子  來進行比喻 這次一樣 假設我們是一個顧車的人士 我們有很多台車子要顧 那由於我們顧車會需要得知許多車子各自的特性 哪一廠牌 哪一車款 總價多少 里程數多少 車子的持有人是誰 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaoop ; /** * * @author chous */ public class Car { //Properties String Type ; int Model ; double Price ; double Mileage ; String Owner ; public Car (){ } public Car ( String Type , int Model , double Price , double Mileage , String Owner ){ this . Type = Type ; this . Model = Model ; this . Price = Price ; this . Mileage = Mileage ; this . Owner = Owner ; } //Methods ...

JAVA程式語法_ArrayList簡單錯誤用法及常發生錯誤介紹_Generic Types泛型_Diamond Operator

圖片
我們先來一個 ArrayList (動態陣列) -> 大小可不固定 不用像Array要先給初始範圍大小 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javageneric ; import java.util.ArrayList ; /** * * @author chous */ public class JavaGeneric { /** * @param args the command line arguments */ public static void main ( String [] args ) { // TODO code application logic here ArrayList myArrList = new ArrayList (); String name1 = "Jack" ; int intNum = 7 ; double douNum = 3.14 ; myArrList . add ( name1 ); myArrList . add ( intNum ); myArrList . add ( douNum ); myArrList . add ( new Object ()); myArrList . add ( new A...

JAVA程式語法_數學運算

圖片
數學運算 先來個  四則運算 搭配  printf  輸出  暖身 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package myapp ; import java.util.Scanner ; /** * * @author chous */ public class MyApp { /** * @param args the command line arguments */ public static void main ( String [] args ) { // TODO code application logic here Scanner input = new Scanner ( System . in ); double d1 , d2 ; System . out . println ( "Please input first double num" ); d1 = input . nextDouble (); System . out . println ( "Please input second double num" ); d2 = input . nextDouble (); double addResult , subRe...