By GokiSoft.com|
20:16 18/07/2022|
Java Advanced
[Source Code] Tìm hiểu về Exception & Collections trong Java - C2108L
#Lighting.java
/*
* 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 java2.lesson01;
/**
*
* @author std
*/
public class Lighting {
enum STATUS {ON, OFF};
STATUS newStatus;
/**
* status:
* 0 -> OFF
* 1 -> ON
*/
int status;
public void checkStatus() {
if(status == 0) {
System.out.println("OFF");
} else {
System.out.println("ON");
}
}
public void checkStatusNew() {
switch(newStatus) {
case ON:
System.out.println("ON");
break;
case OFF:
System.out.println("OFF");
break;
}
}
}
#Main.java
/*
* 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 java2.lesson01;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author std
*/
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap chuoi: ");
String str = scan.nextLine();
String pattern = "[a-kH-W5-9]{3,9}[m-t]{5,10}";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(str);
boolean isFind = false;
while(m.find()) {
System.out.println(m.group() + ", start: " + m.start() + ", end: " + m.end());
isFind = true;
}
if(!isFind) {
System.out.println("Khong tim thay");
}
}
}
#Test.java
/*
* 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 java2.lesson01;
import java.util.ArrayList;
import java.util.Vector;
/**
*
* @author std
*/
public class Test {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
//Nhan xet ve ArrayList
// - Class Object -> Ke thua tu interface List
// - Bien elementData -> Mang index object -> []
// - size: Luu vi tri dang them phan tu vao
// - elementData -> 10 phan tu
list.add(5);
list.add(8);
list.add(9);
for (Integer v : list) {
System.out.println("v = " + v);
}
Vector<Integer> vec = new Vector<>();
vec.add(123);
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)