java递归简易应用教程

package com.xiaohao.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

 

public class Test {



/**
* |-市场部
*   |-宣传部
*   |-业务部
*     |-业务一部
*     |-业务二部
* |-开发部
*   |-开发一部
*   |-开发二部
* @param args
*/



public ArrayList<Department> init() {

Department depart_7=new Department("业务一部", null);
Department depart_8=new Department("业务二部", null);

Department depart_5=new Department("开发一部", null);
Department depart_6=new Department("开发二部", null);

ArrayList<Department> list=new ArrayList<Department>();
list.add(depart_7);
list.add(depart_8);
Department depart_4=new Department("业务部",list);
Department depart_3=new Department("宣传部",null);

ArrayList<Department> list2=new ArrayList<Department>();
list2.add(depart_3);
list2.add(depart_4);
Department depart_1=new Department("市场部",list2);

ArrayList<Department> list3=new ArrayList<Department>();
list3.add(depart_5);
list3.add(depart_6);
Department depart_2=new Department("开发部", list3);

ArrayList<Department> list4=new ArrayList<Department>();
list4.add(depart_1);
list4.add(depart_2);
Department depart_0=new Department("树根",list4);
return (ArrayList<Department>) depart_0.getChildrenDepartment();
}

public void showDepartment(List<Department> list,String prefix){
if(list==null)
return;
prefix=prefix+"  ";
for(Department department:list)
{
System.out.println(prefix+"|-"+department.getName());
showDepartment(department.getChildrenDepartment(),prefix);
}


}

@org.junit.Test
public void test(){
ArrayList<Department> list=init();
showDepartment(list," ");
}

public static void main(String[] args) {
Locale[] locals=Locale.getAvailableLocales();
System.out.println("java所支持的所有语言如下:");
System.out.println("--------------------------------------------------------------------");
for(Locale local:locals)
{
System.out.println(local.getDisplayLanguage());
}
System.out.println("--------------------------------------------------------------------");

Locale local=Locale.getDefault();
ResourceBundle resource=ResourceBundle.getBundle("com.xiaohao.test.xiaohao", local);
System.out.println(resource.getString("userName"));

}
}

你可能感兴趣的:(java)