├── Phase1 ├── AndOrNot.java ├── Assignment1.java ├── Assignment2.java ├── Assignment3.java ├── Assignment4.java ├── Assignment5.java ├── Assignment6.java ├── Assignment7.java ├── BreakContinue.java ├── CompareTutorial.java ├── Compound.java ├── Demo.java ├── Display.java ├── DoWhileLoop.java ├── Escape.java ├── ForLoop.java ├── HelloWorld.java ├── IfStatement.java ├── InputNextLine.java ├── InputTutorial.java ├── LogicTutorial.java ├── MathOperator.java ├── MinmaxLoop.java ├── ModLoop.java ├── Multiply.java ├── NestedIf.java ├── NestedLoop.java ├── Prepost.java ├── SummationLoop.java ├── SwitchCase.java ├── Ternary.java ├── Test.java ├── Variable.java └── WhileLoop.java ├── Phase2 ├── Array & Exception │ ├── ArrayBasic1.java │ ├── CharacterMethod.java │ ├── Demo.java │ ├── ExceptionDemo1.java │ ├── Method1.java │ ├── MethodReturn.java │ ├── StringMethod.java │ ├── StringMethod2.java │ ├── ThrowDemo.java │ └── VariableArg.java └── Input & Output │ ├── CalculateGrade.java │ ├── Demo.java │ ├── FileDemo1.java │ ├── FileDemo2.java │ ├── Grade.txt │ ├── Introduction.txt │ ├── MathDemo.java │ └── Score.txt ├── Phase3 ├── Collections │ ├── ArrayList │ │ └── Program.java │ ├── HashMap │ │ └── Program.java │ └── HashSet , LinkedHashSet , TreeSet │ │ └── Program.java ├── Enum │ └── Program.java └── Generic │ ├── Bounded Type Parameter │ └── Program.java │ ├── Generic Classes │ └── Program.java │ ├── Generic Method │ └── Program.java │ └── Multiple Type Parameter │ └── Program.java ├── README.md └── img └── fahrenheit_to_celsius_formulas.png /Phase1/AndOrNot.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class AndOrNot{ 3 | public static void main(String[] args) { 4 | Scanner kb = new Scanner(System.in); 5 | System.out.print("ป้อนอายุของคุณ : "); 6 | int age=kb.nextInt(); 7 | 8 | if(!(age==15)){ 9 | System.out.println("วัยรุ่น"); 10 | }else{ 11 | System.out.println("วัยเด็ก"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Phase1/Assignment1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Assignment1{ 3 | public static void main(String[] args) { 4 | Scanner sc=new Scanner(System.in); 5 | System.out.print("ป้อนน้ำหนัก (kg) :"); 6 | double weight=sc.nextDouble(); 7 | System.out.print("ป้อนส่วนสูง (cm) :"); 8 | double height=sc.nextDouble(); 9 | height/=100; // height=height/100; 10 | 11 | double bmi=weight/(height*height); 12 | 13 | System.out.println("น้ำหนัก = "+weight); 14 | System.out.println("ส่วนสูง = "+height); 15 | System.out.println("ค่าดัชนีมวลกาย (BMI) = "+bmi); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Phase1/Assignment2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Assignment2{ 3 | //เขียนโปรแกรมเปรียบเทียบตัวเลข 4 | public static void main(String[] args) { 5 | Scanner kb=new Scanner(System.in); 6 | System.out.print("ป้อนตัวเลขที่ 1 = "); 7 | int number1=kb.nextInt(); 8 | System.out.print("ป้อนตัวเลขที่ 2 = "); 9 | int number2=kb.nextInt(); 10 | 11 | if(number1>number2){ 12 | System.out.println(number1+" มากกว่า "+number2); 13 | }else if(number1=18.5 && bmi<=22.9){ 22 | predict = "สมส่วน"; 23 | } 24 | else if(bmi>=23.0 && bmi<=24.9){ 25 | predict = "น้ำหนักเกิน"; 26 | } 27 | else if(bmi>=25.0 && bmi<=29.9){ 28 | predict = "โรคอ้วน"; 29 | }else if(bmi>=30.0 && bmi<=70.0){ 30 | predict = "โรคอ้วนระดับอันตราย"; 31 | }else{ 32 | predict = "ไม่ทราบค่า"; 33 | } 34 | System.out.println("ทำนายผล = "+predict); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Phase1/Assignment6.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Assignment6{ 3 | public static void main(String[] args) { 4 | Scanner kb=new Scanner(System.in); 5 | System.out.print("ป้อนจำนวนเงิน = "); 6 | int money=kb.nextInt(); 7 | System.out.println("จำนวนเงิน = "+money); 8 | 9 | if(money>=1000){ 10 | // 5000/1000 = จำนวนแบงค์พัน 11 | System.out.println("1000 บาท = "+(money/1000) +" ใบ"); 12 | money%=1000; 13 | } 14 | if(money>=500){ 15 | System.out.println("500 บาท = "+(money/500) +" ใบ"); 16 | money%=500; 17 | } 18 | if(money>=100){ 19 | System.out.println("100 บาท = "+(money/100) +" ใบ"); 20 | money%=100; 21 | } 22 | if(money>=50){ 23 | System.out.println("50 บาท = "+(money/50) +" ใบ"); 24 | money%=50; 25 | } 26 | if(money>=20){ 27 | System.out.println("20 บาท = "+(money/20) +" ใบ"); 28 | money%=20; 29 | } 30 | if(money>=10){ 31 | System.out.println("10 บาท = "+(money/10) +" เหรียญ"); 32 | } 33 | } 34 | } 35 | 36 | 37 | /* 38 | โปรแกรมแลกธนบัตร 39 | ประกอบด้วย => 1000 , 500 ,100 ,50 ,20 40 | 41 | เช่น 42 | ################## 43 | 2000 จะได้ 44 | แบงค์ 1000 = 2 ใบ 45 | ################## 46 | 1500 จะได้ 47 | แบงค์ 1000 = 1 ใบ 48 | แบงค์ 500 = 1 ใบ 49 | ################## 50 | 1800 จะได้ 51 | แบงค์ 1000 = 1 ใบ 52 | แบงค์ 500 = 1 ใบ 53 | แบงค์ 100 = 3 ใบ 54 | ################## 55 | 100 จะได้ 56 | แบงค์ 100 = 1 ใบ 57 | ################## 58 | 90 จะได้ 59 | แบงค์ 50 = 1 ใบ 60 | แบงค์ 20 = 2 ใบ 61 | ################## 62 | 70 จะได้ 63 | แบงค์ 50 = 1 ใบ 64 | แบงค์ 20 = 1 ใบ 65 | ################## 66 | */ 67 | -------------------------------------------------------------------------------- /Phase1/Assignment7.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Assignment7{ 3 | public static void main(String[] args) { 4 | Scanner kb=new Scanner(System.in); 5 | // System.out.print("ป้อนอุณหภูมิ (ฟาเรนไฮน์) = "); 6 | // float fahren=kb.nextFloat(); 7 | // float cel = (fahren-32)*5/9; 8 | // System.out.println(fahren+" องศาฟาเรนไฮน์ = "+ cel +" องศาเซลเซียส"); 9 | 10 | System.out.print("ป้อนอุณหภูมิ (เซลเซียส) = "); 11 | float cel=kb.nextFloat(); 12 | 13 | float fahren = (cel*9/5)+32; 14 | System.out.println(cel+" องศาเซลเซียส = "+ fahren +" องศาฟาเรนไฮน์"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase1/BreakContinue.java: -------------------------------------------------------------------------------- 1 | class BreakContinue{ 2 | public static void main(String[] args) { 3 | for(int i=1;i<=10;i++){ 4 | if(i%2 == 0)continue; 5 | System.out.println(i); 6 | } 7 | System.out.println("จบโปรแกรม"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Phase1/CompareTutorial.java: -------------------------------------------------------------------------------- 1 | class CompareTutorial{ 2 | public static void main(String[] args) { 3 | // true / false 4 | 5 | int a=10,b=5; 6 | // boolean c=(a==b); 7 | System.out.println(a+" มีค่าเท่ากับ "+b+" หรือไม่ ? = "+(a==b)); 8 | System.out.println(a+" มีค่าไม่เท่ากับ "+b+" หรือไม่ ? = "+(a!=b)); 9 | System.out.println(a+" มีค่ามากกว่า "+b+" หรือไม่ ? = "+(a>b)); 10 | System.out.println(a+" มีค่าน้อยกว่า "+b+" หรือไม่ ? = "+(a ขึ้นบรรทัดใหม่ 5 | \t => tab 6 | */ 7 | System.out.println("Hello\nWorld"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Phase1/ForLoop.java: -------------------------------------------------------------------------------- 1 | class ForLoop{ 2 | public static void main(String[] args) { 3 | //3 ส่วน 4 | // ส่วนตัวแปรเริ่มต้น => ตัวนับรอบ 5 | // เงื่อนไข 6 | // การเพิ่มค่า / ลดค่า 7 | for(int count=10;count>0;count-=2){ 8 | // คำสั่งที่จะทำซ้ำ 9 | System.out.println(count); 10 | // if(count>0)break; 11 | // 10 , 9 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Phase1/HelloWorld.java: -------------------------------------------------------------------------------- 1 | class HelloWorld{ 2 | public static void main(String[] args) { 3 | System.out.println("Hello World"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Phase1/IfStatement.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class IfStatement{ 3 | public static void main(String[] args) { 4 | Scanner kb = new Scanner(System.in); 5 | System.out.print("ป้อนอายุของคุณ : "); 6 | int age=kb.nextInt(); 7 | // 60 8 | if(age>=15 && age<=19){ 9 | System.out.println("วัยรุ่น"); 10 | } 11 | else if(age>=20 && age<=29){ 12 | System.out.println("วัยหนุ่ม/สาว"); 13 | } 14 | else if(age>=30 && age<=39){ 15 | System.out.println("วัยทำงาน"); 16 | } 17 | else if(age>=40 && age<=59){ 18 | System.out.println("วัยกลางคน"); 19 | } 20 | else if(age>=60){ 21 | System.out.println("วัยชรา"); 22 | }else{ 23 | System.out.println("ไม่พบช่วงอายุ"); 24 | } 25 | System.out.println("จบโปรแกรม"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Phase1/InputNextLine.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class InputNextLine{ 3 | public static void main(String[] args) { 4 | Scanner sc=new Scanner(System.in); 5 | System.out.print("ป้อนชื่อของคุณ = "); 6 | String name=sc.nextLine(); //อ่านข้อความที่รับจากแป้นพิมพ์ทั้งบรรทัด 7 | System.out.println("ชื่อของคุณ คือ = "+name); // แสดงข้อความที่พิมพ์ 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Phase1/InputTutorial.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class InputTutorial{ 3 | public static void main(String[] args) { 4 | // รับค่าข้อมูล 5 | // ข้อมูลแบบไหน ? ตัวเลข integer ,float , long , double , ข้อความ string 6 | // ข้อความทำอะไร 7 | // ข้อความแบบตัวเลข => คำนวณได้ | คำนวณไม่ได้ 8 | 9 | // ประกาศใช้งาน Class | new 10 | Scanner sc=new Scanner(System.in); 11 | System.out.print("ป้อนชื่อของคุณ = "); 12 | String name=sc.nextLine(); // รับค่า String จากแป้นพิมพ์ => name 13 | 14 | System.out.print("ป้อนปีเกิด พ.ศ = "); 15 | double year=sc.nextDouble();// รับค่า integer จากแป้นพิมพ์ =>year 16 | 17 | double age= 2563 - year;// คำนวณอายุ 18 | 19 | System.out.println("ชื่อของคุณ คือ = "+name); // แสดงข้อความที่พิมพ์ 20 | System.out.println("ปีเกิด = "+year); 21 | System.out.println("อายุ = "+age); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Phase1/LogicTutorial.java: -------------------------------------------------------------------------------- 1 | class LogicTutorial{ 2 | public static void main(String[] args) { 3 | /* 4 | AND && => และ 5 | OR || => หรือ 6 | NOT ! => ไม่ (ตรงกันข้าม) 7 | */ 8 | 9 | int a=10,b=20; 10 | 11 | System.out.println(!(a==b)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Phase1/MathOperator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class MathOperator{ 3 | public static void main(String[] args) { 4 | Scanner sc=new Scanner(System.in); 5 | System.out.print("ป้อนตัวเลขที่ 1 = "); 6 | int a=sc.nextInt(); 7 | System.out.print("ป้อนตัวเลขที่ 2 = "); 8 | int b=sc.nextInt(); 9 | 10 | System.out.println("ผลบวก = "+(a+b)); 11 | System.out.println("ผลลบ = "+(a-b)); 12 | System.out.println("ผลคูณ = "+(a*b)); 13 | System.out.println("ผลหาร = "+(a/b)); 14 | System.out.println("เศษ = "+(a%b)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase1/MinmaxLoop.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class MinmaxLoop{ 3 | public static void main(String[] args) { 4 | Scanner kb=new Scanner(System.in); 5 | int maxNumber=0,minNumber=Integer.MAX_VALUE; 6 | while(true){ 7 | System.out.print("ป้อนตัวเลข = "); 8 | int number=kb.nextInt();//max = 100 9 | if(number<0)break; 10 | if(number>maxNumber) maxNumber=number; 11 | if(number100) break; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Phase2/Array & Exception/ArrayBasic1.java: -------------------------------------------------------------------------------- 1 | class ArrayBasic1{ 2 | public static void main(String[] args) { 3 | // Array 2 มิติ 4 | String [][] products ={ 5 | {"เก้าอี้","โต๊ะ","โคมไฟ"}, 6 | {"คีย์บอร์ด","เม้าส์","แป้นพิมพ์"}, 7 | {"ลิปติก","โรลออน","ครีม"} 8 | }; 9 | for(int row = 0 ;rowbalance){ 17 | throw new Exception("ยอดเงินในบัญชีไม่พอ"); 18 | } 19 | balance -=money; 20 | System.out.println("ยอดเงินคงเหลือ = "+balance); 21 | } 22 | } -------------------------------------------------------------------------------- /Phase2/Array & Exception/ExceptionDemo1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class ExceptionDemo1{ 3 | public static void main(String[] args) { 4 | try { 5 | Scanner kb =new Scanner(System.in); 6 | System.out.print("ป้อนตัวเลข = "); 7 | int number=kb.nextInt(); 8 | System.out.println(number); 9 | 10 | }catch(Exception e){ 11 | e.printStackTrace(); 12 | }finally{ 13 | //คำสั่งอื่นๆ 14 | System.out.println("ทำงานอย่างอื่นไปๆ..."); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Phase2/Array & Exception/Method1.java: -------------------------------------------------------------------------------- 1 | class Method1{ 2 | public static void main(String[] args) { 3 | int [] numberA = {10,20,30,50,100,200}; 4 | String [] fruit = {"มะม่วง","ขนุน","น้อยหน่า"}; 5 | System.out.println(searchFruit(fruit,"ขนุน")); 6 | } 7 | 8 | // แสดงผลตัวเลขใน array ที่ส่งเข้ามาทำงานในเมธอด 9 | static void displayArray(int [] arr){ 10 | System.out.print("{"); 11 | for(int i=0;imaxValue){ 26 | maxValue=arr[i]; 27 | } 28 | } 29 | return maxValue; 30 | } 31 | 32 | static int findMinInArray(int [] arr){ 33 | int minValue = arr[0] ;//เก็บค่าต่ำสุดเอาไว้เป็นค่าเริ่มต้น 34 | for(int i= 0; iarr[maxIndex]){ 45 | maxIndex=i; 46 | } 47 | } 48 | return maxIndex; 49 | } 50 | 51 | static int findMinIndex(int [] arr){ 52 | int minIndex=0;//เก็บตำแหน่ง Index สมาชิกที่มีค่าตัวเลขน้อยที่สุดใน arr 53 | for(int i=0;i ต่อ String 10 | // String result=name+city; 11 | // System.out.println(result.concat(".com")); 12 | 13 | // หาความยาว String 14 | // int count = name.length(); 15 | // System.out.println(count); 16 | 17 | 18 | // หาตำแหน่งตัวอักษร (เลขตำแหน่ง) 19 | // System.out.println(name.charAt(3)); 20 | 21 | // เปรียบเทียบ String 22 | // if(name1.equalsIgnoreCase(name2)){ 23 | // System.out.println("เหมือนกัน"); 24 | // }else{ 25 | // System.out.println("ไม่เหมือนกัน"); 26 | // } 27 | 28 | String fullName ="ก้อง รักสยาม"; 29 | String code ="6078930JP"; 30 | 31 | // if(fullName.startsWith("นาย")){ 32 | // System.out.println("ชาย"); 33 | // }else{ 34 | // System.out.println("หญิง"); 35 | // } 36 | 37 | // boolean result = code.endsWith("JP"); 38 | // if(result){ 39 | // System.out.println("ประเทศญี่ปุ่น"); 40 | // }else{ 41 | // System.out.println("ประเทศไทย"); 42 | // } 43 | int result = fullName.indexOf("java"); 44 | System.out.println(result); 45 | } 46 | } -------------------------------------------------------------------------------- /Phase2/Array & Exception/StringMethod2.java: -------------------------------------------------------------------------------- 1 | class StringMethod2{ 2 | public static void main(String[] args) { 3 | // String message = "Happy New Year 2020 | Happy Birth Day 2020"; 4 | // message = message.replaceFirst("2020","2021"); 5 | 6 | 7 | // String = > Array ต้องใช้สัญลักษณ์ 8 | // String data ="มะม่วง,มะยม,ขนุน,น้อยหน่า"; 9 | // String [] fruit = data.split(" "); 10 | // System.out.println(fruit[0]); 11 | 12 | // String name ="kongruksiam"; 13 | // subString(เริ่มนับที่ 0 , จุดสุดท้าย - 1); 14 | // String word = name.substring(1); // 0 - 2 15 | // System.out.println(word); 16 | 17 | // String => Array Character 18 | // String name ="kongruksiam"; 19 | // char [] alphabet = name.toCharArray(); 20 | // System.out.println(alphabet[2]); 21 | 22 | // Array Character => String 23 | // char [] name = {'k','o','n','g'}; 24 | // String result = String.copyValueOf(name); 25 | // System.out.println(result); 26 | 27 | // String name =" kongruksiam "; 28 | // System.out.println(name.length()); 29 | // System.out.println(name); 30 | 31 | // name = name.trim(); 32 | // System.out.println(name.length()); 33 | // System.out.println(name); 34 | 35 | // String name ="KONGRUKSIAM"; 36 | // System.out.println(name.toLowerCase()); 37 | int number = 100; 38 | double number2 = 3.1456; 39 | String result = String.valueOf(number2); 40 | System.out.println(result); 41 | } 42 | } -------------------------------------------------------------------------------- /Phase2/Array & Exception/ThrowDemo.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class ThrowDemo{ 3 | static int balance = 5000; 4 | public static void main(String[] args) { 5 | try { 6 | 7 | Scanner kb=new Scanner(System.in); 8 | System.out.print("ป้อนจำนวนเงินที่ต้องการถอน = "); 9 | int money = kb.nextInt(); 10 | //ถอนเงิน 11 | withDraw(money); 12 | } catch (Exception e) { 13 | e.printStackTrace(); 14 | } 15 | } 16 | public static void withDraw(int amount) throws Exception{ 17 | // จำนวนเงินที่ถอน 18 | if(amount<=0){ 19 | throw new Exception("กรุณาป้อนจำนวนเงินมากกว่า 0"); 20 | } 21 | if(amount>balance){ 22 | throw new Exception("ยอดเงินคงเหลือไม่พอ"); 23 | } 24 | balance-=amount; 25 | System.out.println("ถอนเงิน = "+amount); 26 | System.out.println("ยอดคงเหลือ = "+balance); 27 | } 28 | } -------------------------------------------------------------------------------- /Phase2/Array & Exception/VariableArg.java: -------------------------------------------------------------------------------- 1 | class VariableArg{ 2 | public static void main(String[] args) { 3 | summation(10,20,30); 4 | } 5 | public static void summation(int...number){ 6 | int sum=0; 7 | for(int i=0;i=80){ 21 | grade = "A"; 22 | }else if(score>=70){ 23 | grade = "B"; 24 | } 25 | else if(score>=60){ 26 | grade = "C"; 27 | } 28 | else if(score>=50){ 29 | grade = "D"; 30 | }else{ 31 | grade = "F"; 32 | } 33 | output.println(nisit+" "+grade); 34 | } 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | output.close(); 39 | } 40 | } -------------------------------------------------------------------------------- /Phase2/Input & Output/Demo.java: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Phase2/Input & Output/FileDemo1.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class FileDemo1{ 3 | public static void main(String[] args) { 4 | // File f=new File("Demo.txt"); 5 | try { 6 | FileWriter writer = new FileWriter(new File("Introduction.txt")); 7 | BufferedWriter bw = new BufferedWriter(writer); 8 | bw.write("สวัสดีครับผม\n"); 9 | bw.write("เขียนโปรแกรมภาษา Java เบื้องต้น\n"); 10 | bw.write("สอนโดยก้องรักสยาม"); 11 | // writer.close(); 12 | bw.close(); 13 | System.out.println("เขียนไฟล์เสร็จแล้ว!"); 14 | } catch (Exception e) { 15 | e.printStackTrace(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Phase2/Input & Output/FileDemo2.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class FileDemo2{ 3 | public static void main(String[] args) { 4 | try { 5 | FileReader reader=new FileReader(new File("Introduction.txt")); 6 | BufferedReader br =new BufferedReader(reader); 7 | String message=""; 8 | 9 | while((message=br.readLine()) !=null){ 10 | System.out.println(message); 11 | } 12 | 13 | } catch (Exception e) { 14 | e.printStackTrace(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Phase2/Input & Output/Grade.txt: -------------------------------------------------------------------------------- 1 | NISIT60101 60 C 2 | NISIT60102 70 B 3 | NISIT60103 85 A 4 | NISIT60104 40 F 5 | NISIT60105 35 F 6 | NISIT60106 50 D 7 | -------------------------------------------------------------------------------- /Phase2/Input & Output/Introduction.txt: -------------------------------------------------------------------------------- 1 | สวัสดีครับผม 2 | เขียนโปรแกรมภาษา Java เบื้องต้น 3 | สอนโดยก้องรักสยาม -------------------------------------------------------------------------------- /Phase2/Input & Output/MathDemo.java: -------------------------------------------------------------------------------- 1 | import java.lang.Math; 2 | class MathDemo{ 3 | public static void main(String[] args) { 4 | // ค่าคงที่ใน ClassMath; 5 | // System.out.println(Math.PI); 6 | // System.out.println(Math.E); 7 | // int r = 2; 8 | // double area = Math.PI * r *r; 9 | // System.out.println(area); 10 | 11 | 12 | // int number = -30; 13 | // System.out.println(Math.abs(number)); 14 | 15 | //ปัดเศษ 16 | double number = 14.4; 17 | System.out.println(Math.ceil(number));//ปัดขึ้น 18 | System.out.println(Math.floor(number));//ปัดลง 19 | 20 | // <= .5 ปัดลง 21 | // > 0.5 ปัดขึ้น 22 | System.out.println(Math.rint(number)); 23 | 24 | 25 | // >= .5 ปัดขึ้น 26 | // <= .4 ปัดลง 27 | System.out.println(Math.round(15.4)); 28 | System.out.println(Math.round(15.5)); 29 | System.out.println(Math.round(15.6)); 30 | 31 | 32 | // หาจากที่ 2 33 | System.out.println("หารากที่ 2 ของ 9 = "+Math.sqrt(9)); 34 | System.out.println("หารากที่ 2 ของ 25 = "+Math.sqrt(25)); 35 | 36 | // หาค่ายกกำลัง 37 | System.out.println(Math.pow(5,4)); 38 | 39 | // หาค่ามากสุดในชุดตัวเลข 40 | int result = Math.max(10,20,40,800,100); 41 | System.out.println("ค่าที่มากที่สุด คือ "+result); 42 | } 43 | } -------------------------------------------------------------------------------- /Phase2/Input & Output/Score.txt: -------------------------------------------------------------------------------- 1 | NISIT60101 60 2 | NISIT60102 70 3 | NISIT60103 85 4 | NISIT60104 40 5 | NISIT60105 35 6 | NISIT60106 50 -------------------------------------------------------------------------------- /Phase3/Collections/ArrayList/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | import java.util.ArrayList; 3 | import java.util.List; 4 | public class Program { 5 | public static void main(String[] args) { 6 | ArrayList data = new ArrayList<>(); 7 | ArrayList newdata = new ArrayList<>(List.of("C","C++","C#")); 8 | data.add("Java"); 9 | data.add("PHP"); 10 | data.add("Python"); 11 | data.add(1,"SQL"); 12 | // data.set(0, "JavaScript"); 13 | data.addAll(0,newdata); 14 | data.remove(1); 15 | data.remove("SQL"); 16 | // data.clear(); 17 | // System.out.println(data.contains("C++")); 18 | System.out.println(data.indexOf("C++")); 19 | System.out.println(data); 20 | } 21 | } -------------------------------------------------------------------------------- /Phase3/Collections/HashMap/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | import java.util.*; 3 | public class Program { 4 | public static void main(String[] args) { 5 | HashMap countries = new HashMap<>(); 6 | countries.put("TH","Thailand"); 7 | countries.put("JP", "Japan"); 8 | countries.put("CN", "China"); 9 | countries.remove("CN"); 10 | // countries.clear(); 11 | // System.out.println(countries.containsValue("Lao")); 12 | System.out.println(countries); 13 | System.out.println(countries.size()); 14 | HashMap confirm = new HashMap<>(); 15 | confirm.put(true,"OK"); 16 | confirm.put(false, "Cancel"); 17 | System.out.println(confirm); 18 | } 19 | } -------------------------------------------------------------------------------- /Phase3/Collections/HashSet , LinkedHashSet , TreeSet/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | import java.util.*; 3 | public class Program { 4 | public static void main(String[] args) { 5 | // HashSet data = new HashSet<>(); 6 | // LinkedHashSet data = new LinkedHashSet<>(); 7 | TreeSet data = new TreeSet<>(); 8 | data.add("Java"); 9 | data.add("PHP"); 10 | data.add("Python"); 11 | data.add("C#"); 12 | data.add("Dart"); 13 | data.add("Assembly"); 14 | data.add("PHP"); 15 | data.add("R"); 16 | data.add("Go"); 17 | // data.remove("PHP"); 18 | // data.clear(); 19 | System.out.println(data); 20 | System.out.println(data.size()); 21 | } 22 | } -------------------------------------------------------------------------------- /Phase3/Enum/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | enum Grade { 3 | A(4.0,"Genius"), 4 | B(3.0,"Very Good"), 5 | C(2.0,"Good"), 6 | D(1.0,"Not Bad"), 7 | F(0.0,"Fail"); 8 | 9 | private Grade(double p,String comment) { 10 | this.point = p; 11 | this.description=comment; 12 | } 13 | public final double point; 14 | public final String description; 15 | } 16 | public class Program { 17 | public static void main(String[] args) { 18 | Grade myGrade = Grade.F; 19 | System.out.println("Grade = "+myGrade+" , "+myGrade.point); 20 | System.out.println("Result = "+myGrade.description); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Phase3/Generic/Bounded Type Parameter/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | class Item{ 3 | T data; 4 | public Item(T value){ 5 | data=value; 6 | } 7 | } 8 | public class Program { 9 | public static void main(String[] args) { 10 | Item obj1=new Item<>(99); 11 | System.out.println(obj1.data); 12 | Item obj2=new Item<>(10.5); 13 | System.out.println(obj2.data); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Phase3/Generic/Generic Classes/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | class Item{ 3 | T data; 4 | public Item(T value){ 5 | data=value; 6 | } 7 | } 8 | public class Program { 9 | public static void main(String[] args) { 10 | Item obj1=new Item<>(99); 11 | System.out.println(obj1.data); 12 | Item obj2=new Item<>(10.5); 13 | System.out.println(obj2.data); 14 | Item obj3 = new Item<>("Kong"); 15 | System.out.println(obj3.data); 16 | Item obj4=new Item<>(true); 17 | System.out.println(obj4.data); 18 | Item obj5=new Item<>('C'); 19 | System.out.println(obj5.data); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Phase3/Generic/Generic Method/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | class Data{ 3 | static void showArray(T[] arr){ 4 | for(T element : arr){ 5 | System.out.println(element); 6 | } 7 | System.out.println("----------------"); 8 | } 9 | } 10 | public class Program { 11 | public static void main(String[] args) { 12 | Data.showArray(new String[]{"Python","Java","PHP"}); 13 | Data.showArray(new Integer[]{10,20,30}); 14 | Data.showArray(new Double[]{10.5,20.3,30.4}); 15 | Data.showArray(new Boolean[]{true,false,true,true}); 16 | } 17 | } -------------------------------------------------------------------------------- /Phase3/Generic/Multiple Type Parameter/Program.java: -------------------------------------------------------------------------------- 1 | package learningjavabasic; 2 | 3 | class Person { 4 | T name; 5 | U age; 6 | public Person(T name, U age) { 7 | this.name = name; 8 | this.age = age; 9 | } 10 | } 11 | 12 | class Product { 13 | T name; 14 | U price; 15 | public Product(T name, U price) { 16 | this.name = name; 17 | this.price = price; 18 | } 19 | } 20 | 21 | public class Program { 22 | public static void main(String[] args) { 23 | // Person obj1=new Person<>("kong",30); 24 | // System.out.println(obj1.name); 25 | // System.out.println(obj1.age); 26 | Product product1 = new Product<>("Mouse", 100); 27 | Product product2 = new Product<>("Keyboard", 199.99); 28 | } 29 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | [![Youtube KongRuksiam Official](https://youtube-stats-card.vercel.app/api?channelid=UCQ1r_4x-P-fETLIU4pqf98w&theme=dark&layout=extruded)](https://www.youtube.com/@KongRuksiamOfficial) 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | kongruksiamza 26 | 27 |
28 | -------------------------------------------------------------------------------- /img/fahrenheit_to_celsius_formulas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongruksiamza/JavaBasic/e2cffecae2411351d276739c2f6ae8db6153b0bd/img/fahrenheit_to_celsius_formulas.png --------------------------------------------------------------------------------