对象怎么来
结构型模式–>对象和谁有关
行为型模式–>对象与对象在干嘛
工厂方法
public interface ISender {
void Send();
}
--------------------------------------------------------------------------------------
public class MailSender implements ISender {
public void Send() {
System.out.println("this is MailSender haha");
}
}
--------------------------------------------------------------------------------------
public class SmsSender implements ISender {
public void Send() {
System.out.println("this is SmsSender haha");
}
}
--------------------------------------------------------------------------------------
public interface IProvider {
ISender produce();
}
--------------------------------------------------------------------------------------
public class SendMailFactory implements IProvider {
public ISender produce() {
return new MailSender();
}
}
--------------------------------------------------------------------------------------
public class SendSmsFactory implements IProvider {
public ISender produce() {
return new SmsSender();
}
}
--------------------------------------------------------------------------------------
public class SendFactory {
public ISender produce(String type) {
if ("mail".equals(type)) {
return new MailSender();
} else if ("sms".equals(type)) {
return new SmsSender();
} else {
System.out.println("请输入正确的类型!");
return null;
}
}
public ISender produceMail() {
return new MailSender();
}
public ISender produceSms() {
return new SmsSender();
}
public static ISender produceMail_1() {
return new MailSender();
}
public static ISender produceSms_1() {
return new SmsSender();
}
public static void main(String[] args) {
SendFactory sendFactory = new SendFactory();
sendFactory.produce("mail").Send();
sendFactory.produce("sms").Send();
sendFactory.produceMail().Send();
sendFactory.produceSms().Send();
SendFactory.produceMail_1().Send();
SendFactory.produceSms_1().Send();
new SendSmsFactory().produce().Send();
new SendMailFactory().produce().Send();
}
}
抽象工厂
原型
public class Prototype implements Cloneable, Serializable {
private static final long serialVersionUID = 1L;
private String string;
private SerializableObject obj;
public Object clone() throws CloneNotSupportedException {
Prototype proto = (Prototype) super.clone();
return proto;
}
public Object deepClone() throws IOException, ClassNotFoundException {
ByteArrayOutputStream bos=new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(bos);
oos.writeObject(this);
ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois=new ObjectInputStream(bis);
return ois.readObject();
}
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
public SerializableObject getObj() {
return obj;
}
public void setObj(SerializableObject obj) {
this.obj = obj;
}
class SerializableObject implements Serializable {
private static final long serialVersionUID = 1L;
}
}
----------------------------------------------------
public class Test_Prototype {
public static void main(String[] args) {
Prototype prototype = new Prototype();
prototype.setString("kevin");
System.out.println("prototype=" + prototype+",--"+prototype.getString());
try {
Prototype p = (Prototype) prototype.clone();
System.out.println("p=" + p);
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
System.out.println("befor------------prototype=" + prototype+",--"+prototype.getString());
try {
prototype.deepClone();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("after------------prototype=" + prototype+",--"+prototype.getString())
}
}
建造者
------------------------------------------------------------
public class Builder {
private List<ISender> list = new ArrayList<ISender>();
public void produceMailSender(int count) {
System.out.println("count=" + count);
for (int i = 0; i < count; i++) {
list.add(new MailSender());
}
System.out.println("MailSender_list" + list.size());
}
public void produceSmsSender(int count) {
System.out.println("count=" + count);
for (int i = 0; i < count; i++) {
list.add(new SmsSender());
}
System.out.println("SmsSender_list" + list.size());
}
public List<ISender> getList() {
return list;
}
public void setList(List<ISender> list) {
this.list = list;
}
}
------------------------------------------------------------
public class Test_builder {
public static void main(String[] args) {
Builder builder = new Builder();
builder.produceMailSender(5);
builder.produceSmsSender(10);
List<ISender> list = builder.getList();
int count_MailSender=0;
int count_SmsSender=0;
for (ISender sender : list) {
if (sender instanceof MailSender) {
count_MailSender++;
} else if (sender instanceof SmsSender) {
count_SmsSender++;
}
}
System.out.println("count_MailSender="+count_MailSender);
System.out.println("count_SmsSender="+count_SmsSender);
}
}
单例
----------------------------------------------------------------------
public class Singleton {
private Singleton() {}
private static class SingletonFactory {
private static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonFactory.instance;
}
public Object readResolve() {
return getInstance();
}
public void print() {
System.out.println("The use of an inner class to maintain the singleton kkkkkkkkk");
}
}
----------------------------------------------------------------------
public class Singleton_1 {
private static Singleton_1 instance = null;
private Singleton_1() {}
public static Singleton_1 getInstance() {
if (instance == null) {
instance = new Singleton_1();
}
return instance;
}
public static synchronized Singleton_1 getInstance_2() {
if (instance == null) {
instance = new Singleton_1();
}
return instance;
}
public static Singleton_1 getInstance_3() {
if (instance == null) {
synchronized (instance) {
if (instance == null) {
instance = new Singleton_1();
}
}
}
return instance;
}
public Object readResolve() {
return instance;
}
public void print() {
System.out.println("Singleton_1 kkkkkkkkk");
}
}
----------------------------------------------------------------------
public class Test_mail {
public static void main(String[] args) {
Singleton_1.getInstance().print();
Singleton_1.getInstance_2().print();
Singleton_1.getInstance_3().print();
Singleton.getInstance().print();
}
}
享元
-----------------------------------------------
public class ConnectionPool {
private Vector<Connection> pool;
public String url = "jdbc:oracle:thin:@192.168.10.22:1521:medi";
public String username = Jdbc_until.username;
public String password = Jdbc_until.password;
public String driverClassName = "oracle.jdbc.driver.OracleDriver";
private int poolSize = 100;
private static ConnectionPool instance = null;
Connection conn = null;
private ConnectionPool() {
pool = new Vector<Connection>(poolSize);
for (int i = 0; i < poolSize; i++) {
try {
Class.forName(driverClassName);
conn = DriverManager.getConnection(url, username, password);
pool.add(conn);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public synchronized void release() {
pool.add(conn);
}
public synchronized Connection getConnection() {
if (pool.size() > 0) {
Connection conn = pool.get(0);
pool.remove(conn);
return conn;
} else {
return null;
}
}
}
-----------------------------------------------
public class Jdbc_until {
public static String url = null;
public static String username = null;
public static String password = null;
public static String driverClassName = null;
static {
Properties p = new Properties();
try {
p.load(Object.class.getClass().getResourceAsStream(
"/jdbc.properties"));
} catch (IOException e) {
e.printStackTrace();
}
driverClassName = p.getProperty("jdbc.driverClassName");
url = p.getProperty("jdbc.url");
username = p.getProperty("jdbc.username");
password = p.getProperty("jdbc.password");
System.out.println(driverClassName);
System.out.println(url);
System.out.println(username);
System.out.println(password);
}
}
桥接
------------------------------------------------------------------
public interface Sourceable {
void method();
}
------------------------------------------------------------------
public class SourceSub1 implements Sourceable {
public void method() {
System.out.println("------------SourceSub1 implements Sourceable {-------------");
}
}
------------------------------------------------------------------
public class SourceSub2 implements Sourceable {
public void method() {
System.out.println("------------SourceSub2 implements Sourceable {-------------");
}
}
------------------------------------------------------------------
public abstract class Bridge {
private Sourceable source;
public void getMethod(){
source.method();
}
public Sourceable getSource() {
return source;
}
public void setSource(Sourceable source) {
this.source = source;
}
}
------------------------------------------------------------------
public class MyBridge extends Bridge {
public void method(){
}
}
------------------------------------------------------------------
public class Test_Bridge {
public static void main(String[] args) {
MyBridge myBridge=new MyBridge();
myBridge.setSource(new SourceSub1());
myBridge.getMethod();
myBridge.setSource(new SourceSub2());
myBridge.getMethod();
}
}
组合
public class TreeNode {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public TreeNode(String name) {
super();
this.name = name;
}
private TreeNode parent;
public TreeNode getParent() {
return parent;
}
public void setParent(TreeNode parent) {
this.parent = parent;
}
private Vector<TreeNode> children=new Vector<TreeNode>();
public void add(TreeNode note){
children.add(note);
}
public void remove(TreeNode note){
children.remove(note);
}
public Enumeration<TreeNode> getChildren(){
return children.elements();
}
}
------------------------------------------
public class Tree {
public TreeNode root = null;
public Tree(String name) {
root = new TreeNode(name);
}
public static void main(String[] args) {
Tree a = new Tree("A");
TreeNode b = new TreeNode("B");
TreeNode c = new TreeNode("C");
b.add(c);
a.root.add(b);
}
}
装饰器
----------------------------------------------------------------------------------
public interface Sourceable {
void method();
}
----------------------------------------------------------------------------------
public class Source implements Sourceable {
public void method() {
System.out.println("-----------Source implements Sourceable {------------");
}
}
----------------------------------------------------------------------------------
public class Decorator implements Sourceable {
private Source source;
public void method() {
System.out.println("---------befor-----source.method();--------");
source.method();
System.out.println("---------after-----source.method();-------------");
}
public Decorator(Source source) {
super();
this.source = source;
}
}
----------------------------------------------------------------------------------
public class Test_Decorator {
public static void main(String[] args) {
new Source().method();
new Decorator(new Source()).method();
}
}
适配器
-------------------------------------------------------------------------------
public class Source {
public void method1(){
System.out.println("-----------Source.method1()-----------");
}
}
-------------------------------------------------------------------------------
public interface Targetable {
public void method1();
public void method2();
}
-------------------------------------------------------------------------------
public class Wrapper implements Targetable {
private Source source;
public Wrapper(Source source) {
super();
this.source = source;
}
public void method1() {
source.method1();
}
public void method2() {
System.out.println("------------Wrapper.method2()-----------------");
}
}
-------------------------------------------------------------------------------
public class Adapter extends Source implements Targetable {
public void method2() {
System.out.println("-------------Adapter.method2()-------------");
}
}
-------------------------------------------------------------------------------
public abstract class Wrapper2 implements Targetable {
public void method1() {};
public void method2() {};
}
-------------------------------------------------------------------------------
public class SourceSub1 extends Wrapper2 {
public void method1() {
System.out.println("the sourceable interface's first Sub1!");
};
}
-------------------------------------------------------------------------------
public class SourceSub2 extends Wrapper2 {
public void method2() {
System.out.println("the sourceable interface's second Sub2!");
};
}
-------------------------------------------------------------------------------
public class Test_Adapter {
public static void main(String[] args) {
Adapter adapter=new Adapter();
adapter.method1();
adapter.method2();
Wrapper wrapper=new Wrapper(new Source());
wrapper.method1();
wrapper.method2();
new SourceSub1().method1();
new SourceSub2().method2();
}
}
-------------------------------------------------------------------------------
外观
-------------------------------------------------------------
public class CPU {
public void startup(){
System.out.println("------CPU.startup()----------");
}
public void shutdown(){
System.out.println("------CPU.shutdown()----------");
}
}
-------------------------------------------------------------
public class Disk {
public void startup(){
System.out.println("------Disk.startup()----------");
}
public void shutdown(){
System.out.println("------Disk.shutdown()----------");
}
}
-------------------------------------------------------------
public class Memory {
public void startup(){
System.out.println("------Memory.startup()----------");
}
public void shutdown(){
System.out.println("------Memory.shutdown()----------");
}
}
-------------------------------------------------------------
public class Computer {
private CPU cpu;
private Memory memory;
private Disk disk;
public Computer() {
super();
this.cpu = new CPU();
this.memory = new Memory();
this.disk = new Disk();
}
public void startup(){
cpu.startup();
memory.startup();
disk.startup();
}
public void shutdown(){
cpu.shutdown();
memory.shutdown();
disk.shutdown();
}
public static void main(String[] args) {
Computer c=new Computer();
c.startup();
c.shutdown();
}
}
代理
------------------------------------------------------------------------------
public interface Sourceable {
void method();
}
------------------------------------------------------------------------------
public class Source implements Sourceable {
public void method() {
System.out.println("----------Source implements Sourceable {-------------");
}
}
------------------------------------------------------------------------------
public class Proxy implements Sourceable {
private Source source;
public Proxy() {
super();
this.source = new Source();
}
public void method() {
System.out.println("-------befor----Proxy implements Sourceable {-------");
source.method();
System.out.println("-------after----Proxy implements Sourceable {-------");
}
}
------------------------------------------------------------------------------
public class Test_proxy {
public static void main(String[] args) {
Proxy proxy = new Proxy();
proxy.method();
}
}
过滤
命令command
------------------------------------------------------------------------
public class Receiver {
public void action() {
System.out.println("command received!");
}
}
------------------------------------------------------------------------
public interface Command {
void exe();
}
------------------------------------------------------------------------
public class MyCommand implements Command {
private Receiver receiver;
public MyCommand(Receiver receiver) {
super();
this.receiver = receiver;
}
public void exe() {
receiver.action();
}
}
------------------------------------------------------------------------
public class Invoker {
private Command command;
public Invoker(Command command) {
super();
this.command = command;
}
public void action() {
command.exe();
}
}
------------------------------------------------------------------------
public class Test_Command {
public static void main(String[] args) {
Receiver receiver = new Receiver();
Command command = new MyCommand(receiver);
Invoker invoker = new Invoker(command);
invoker.action();
}
}
责任链chain
----------------------------------------------------------
public interface Handler {
void operator();
}
----------------------------------------------------------
public abstract class AbstractHandler {
private Handler handler;
public Handler getHandler() {
return handler;
}
public void setHandler(Handler handler) {
this.handler = handler;
}
}
----------------------------------------------------------
public class MyHandler extends AbstractHandler implements Handler {
public String name;
public MyHandler(String name) {
super();
this.name = name;
}
public void operator() {
System.out.println("MyHandler=" + name);
if (getHandler() != null) {
getHandler().operator();
}
}
}
----------------------------------------------------------
public class Test_handler {
public static void main(String[] args) {
MyHandler a = new MyHandler("A");
MyHandler b = new MyHandler("b");
MyHandler c = new MyHandler("c");
MyHandler d = new MyHandler("d");
a.setHandler(b);
b.setHandler(c);
c.setHandler(d);
a.operator();
}
}
解释器interpreter
-----------------------------------------------------------------
public class Context {
private int num1;
private int num2;
public Context(int num1, int num2) {
this.num1 = num1;
this.num2 = num2;
}
g/s...
}
-----------------------------------------------------------------
public interface Expression {
public int interpret(Context context);
}
-----------------------------------------------------------------
public class Minus implements Expression {
@Override
public int interpret(Context context) {
return context.getNum1() - context.getNum2();
}
}
-----------------------------------------------------------------
public class Plus implements Expression {
@Override
public int interpret(Context context) {
return context.getNum1() + context.getNum2();
}
}
-----------------------------------------------------------------
public class Test_interpreter {
public static void main(String[] args) {
Context context = new Context(9, 2);
System.out.println(new Plus().interpret(context));
System.out.println(new Minus().interpret(context));
}
}
迭代子iterator
-------------------------------------------------------
public interface Iterator {
public Object previous();
public Object next();
public boolean hasNext();
public Object first();
}
-------------------------------------------------------
public interface Collection {
public Iterator iterator();
public Object get(int i);
public int size();
}
-------------------------------------------------------
public class MyCollection implements Collection {
public String string[] = { "A", "B", "C", "D", "E" };
public MyCollection() {
super();
}
public Object get(int i) {
return string[i];
}
public Iterator iterator() {
return new MyIterator(this);
}
public int size() {
return string.length;
}
}
-------------------------------------------------------
public class MyIterator implements Iterator {
private Collection collection;
private int pos = -1;
public MyIterator(Collection collection) {
this.collection = collection;
}
public Object first() {
return collection.get(0);
}
public boolean hasNext() {
if (pos < collection.size() - 1) {
return true;
} else {
return false;
}
}
public Object next() {
if (pos < collection.size() - 1) {
pos++;
}
return collection.get(pos);
}
public Object previous() {
if (pos > 0) {
pos--;
}
return collection.get(pos);
}
}
-------------------------------------------------------
public class Test {
public static void main(String[] args) {
Collection collection = new MyCollection();
Iterator it = collection.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}
中介者mediator
--------------------------------------------------------------
public interface Mediator {
public void createMediator();
public void workAll();
}
--------------------------------------------------------------
public class MyMediator implements Mediator {
private User user1;
private User user2;
public User getUser1() {
return user1;
}
public User getUser2() {
return user2;
}
public void createMediator() {
user1 = new User1(this);
user2 = new User2(this);
}
public void workAll() {
user1.work();
user2.work();
}
}
--------------------------------------------------------------
public abstract class User {
private Mediator mediator;
public Mediator getMediator() {
return mediator;
}
public User(Mediator mediator) {
this.mediator = mediator;
}
public abstract void work();
}
--------------------------------------------------------------
public class User1 extends User {
public User1(Mediator mediator) {
super(mediator);
}
@Override
public void work() {
System.out.println("user1 exe!");
}
}
--------------------------------------------------------------
public class User2 extends User {
public User2(Mediator mediator) {
super(mediator);
}
@Override
public void work() {
System.out.println("user2 exe!");
}
}
--------------------------------------------------------------
public class Test_Mediator {
public static void main(String[] args) {
Mediator mediator = new MyMediator();
mediator.createMediator();
mediator.workAll();
}
}
观察者observer
--------------------------------------------------------------------------
public interface Subject {
public void add(Observer observer);
public void del(Observer observer);
public void notifyObservers();
public void operation();
}
--------------------------------------------------------------------------
public abstract class AbstractSubject implements Subject {
private Vector<Observer> vector = new Vector<Observer>();
public void add(Observer observer) {
vector.add(observer);
}
public void del(Observer observer) {
vector.remove(observer);
}
public void notifyObservers() {
for (Enumeration<Observer> e = vector.elements(); e.hasMoreElements();) {
e.nextElement().update();
}
}
}
--------------------------------------------------------------------------
public class MySubject extends AbstractSubject {
public void operation() {
System.out.println("-----------------------------MySubject.operation()-- extends AbstractSubject {");
notifyObservers();
}
}
--------------------------------------------------------------------------
public interface Observer {
void update();
}
--------------------------------------------------------------------------
public class Observer1 implements Observer {
public void update() {
System.out.println("-----------Observer1 implements Observer {------------");
}
}
--------------------------------------------------------------------------
public class Observer2 implements Observer {
public void update() {
System.out.println("-----------Observer2 implements Observer {------------");
}
}
-------------------------------------------------------------------------
public class Test {
public static void main(String[] args) {
Subject sub = new MySubject();
sub.add(new Observer1());
sub.add(new Observer2());
sub.operation();
}
}
备忘录memento
public class Memento {
private String value;
public String getValue() {
return value;
}
public Memento(String value) {
super();
this.value = value;
}
public void setValue(String value) {
this.value = value;
}
}
------------------------------------------------------------------
public class Original {
private String value;
public Original(String value) {
super();
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Memento createMemento() {
return new Memento(value);
}
public void restoreMemento(Memento memento) {
this.value = memento.getValue();
}
}
------------------------------------------------------------------
public class Storage {
private Memento memento;
public Memento getMemento() {
return memento;
}
public Storage(Memento memento) {
super();
this.memento = memento;
}
public void setMemento(Memento memento) {
this.memento = memento;
}
}
------------------------------------------------------------------
public class Test_memento {
public static void main(String[] args) {
Original ori = new Original("ogg");
Storage stor = new Storage(ori.createMemento());
System.out.println("---------begin---------");
System.out.println("init : " + ori.getValue());
ori.setValue("niu");
System.out.println("update after : " + ori.getValue());
ori.restoreMemento(stor.getMemento());
System.out.println("restoreMemento : " + ori.getValue());
}
}
模板方法template
-------------------------------------------------------------------
public abstract class AbstractCalculato {
public final int calculate(String exp, String opt) {
int array[] = split(exp, opt);
return calculate(array[0], array[1]);
}
abstract public int calculate(int num1, int num2);
public int[] split(String exp, String opt) {
String array[] = exp.split(opt);
int arrayInt[] = new int[2];
arrayInt[0] = Integer.parseInt(array[0]);
arrayInt[1] = Integer.parseInt(array[1]);
return arrayInt;
}
}
-------------------------------------------------------------------
public class Minus extends AbstractCalculato {
@Override
public int calculate(int num1, int num2) {
return num1 - num2;
}
}
-------------------------------------------------------------------
public class Multiply extends AbstractCalculato {
@Override
public int calculate(int num1, int num2) {
return num1 * num2;
}
}
-------------------------------------------------------------------
public class Plus extends AbstractCalculato {
@Override
public int calculate(int num1, int num2) {
return num1 + num2;
}
}
-------------------------------------------------------------------
public class Test_Template_Method {
public static void main(String[] args) {
AbstractCalculato p = new Plus();
String exp="10+6";
int result=p.calculate(exp, "\\+");
System.out.println("result1="+result);
exp="10-6";
p = new Minus();
result=p.calculate(exp, "\\-");
System.out.println("result2="+result);
exp="10*6";
p = new Multiply();
result=p.calculate(exp, "\\*");
System.out.println("result3="+result);
}
}
访问者visitor
-------------------------------------------------------------------
public interface Subject {
public void accept(Visitor visitor);
public String getSubject();
}
-------------------------------------------------------------------
public class MySubject implements Subject {
public void accept(Visitor visitor) {
visitor.visit(this);
}
public String getSubject() {
return "love";
}
}
-------------------------------------------------------------------
public interface Visitor {
public void visit(Subject sub);
}
-------------------------------------------------------------------
public class MyVisitor implements Visitor {
public void visit(Subject sub) {
System.out.println("visit the subject:" + sub.getSubject());
}
}
-------------------------------------------------------------------
public class Test_Visitor {
public static void main(String[] args) {
Visitor visitor = new MyVisitor();
Subject sub = new MySubject();
sub.accept(visitor);
}
}
状态state
------------------------------------------------------------
public class State {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public void method1() {
System.out.println("execute the first opt!");
}
public void method2() {
System.out.println("execute the second opt!");
}
}
------------------------------------------------------------
public class Context {
private State state;
public Context(State state) {
this.state = state;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public void method() {
if (state.getValue().equals("state1")) {
state.method1();
} else if (state.getValue().equals("state2")) {
state.method2();
}
}
}
------------------------------------------------------------
public class Test_State {
public static void main(String[] args) {
State state = new State();
Context context = new Context(state);
state.setValue("state1");
context.method();
state.setValue("state2");
context.method();
}
}
策略strategy
-------------------------------------------------------------
public interface ICalculator {
int calculate(String exp);
}
-------------------------------------------------------------
public abstract class AbstractCalculator {
public int[] split(String exp, String opt) {
String array[] = exp.split(opt);
int arrayInt[] = new int[2];
arrayInt[0] = Integer.parseInt(array[0]);
arrayInt[1] = Integer.parseInt(array[1]);
return arrayInt;
}
}
-------------------------------------------------------------
public class Minus extends AbstractCalculator implements ICalculator {
public int calculate(String exp) {
int arrayInt[] = split(exp, "\\+");
return arrayInt[0] - arrayInt[1];
}
}
-------------------------------------------------------------
public class Multiply extends AbstractCalculator implements ICalculator {
public int calculate(String exp) {
int arrayInt[] = split(exp, "\\+");
return arrayInt[0] * arrayInt[1];
}
}
-------------------------------------------------------------
public class Plus extends AbstractCalculator implements ICalculator {
public int calculate(String exp) {
int arrayInt[] = split(exp, "\\+");
return arrayInt[0] + arrayInt[1];
}
}
-------------------------------------------------------------
public class Test {
public static void main(String[] args) {
String exp = "8+2";
ICalculator cal = new Plus();
int result = cal.calculate(exp);
System.out.println(result);
cal = new Minus();
result = cal.calculate(exp);
System.out.println(result);
cal = new Multiply();
result = cal.calculate(exp);
System.out.println(result);
}
}