/*介面List分為LinkedList和ArrayList;泛型<String>規定該類new出的對象或聲明的引用只能存放String類的對象 eg:List<String> map = new LinkedList<String>(); List<Integer> map = new Linke ...
/*介面List分為LinkedList和ArrayList;泛型<String>規定該類new出的對象或聲明的引用只能存放String類的對象
eg:List<String> map = new LinkedList<String>();
List<Integer> map = new LinkedList<Integer>();
*/
package test1.com.test;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.List;
//import java.util.Collection;
public class Test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<String> map = new LinkedList<String>(); //聲明一個父類引用去指向一個子類對象
//或Collection<String> map = new LinkedList<String>();
map.add("lyb");//map中增加用戶名‘lyb’
secret s = new secret();
s.x = 3;
while(true) {
Scanner sc = new Scanner(System.in);
String add = sc.next();
if(map.contains(add)) {//測試add(即輸入的用戶名)是否包含在map容器中
s.display();
}else {
s.display_jiami();
}
}
}
}
package test1.com.test;
public class secret {
int x;
public void display_jiami() {
System.out.println(x << 1);//對x進行加密處理
}
public void display() {
System.out.println(x);
}
}