Chinaunix首页 | 论坛 | 博客
  • 博客访问: 502942
  • 博文数量: 184
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1172
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-21 13:40
个人简介

技术改变命运

文章分类

全部博文(184)

文章存档

2020年(16)

2017年(12)

2016年(156)

我的朋友

分类: Java

2017-07-20 22:03:43


点击(此处)折叠或打开

  1. interface command
  2. {
  3.     public abstract int process(int[] a);
  4. }
  5. public class CommandTest
  6. {
  7.     int[] target = {1,2,3,4};
  8.     public void process(int[] a,command c)
  9.     {
  10.         System.out.println("元素之和是"+c.process(target));
  11.     }
  12.     public static void main(String[] args)
  13.     {
  14.         CommandTest ct = new CommandTest();
  15.         int[] target = {1,2,3,4};
  16.         ct.process(target,new command()
  17.         {
  18.             public int process(int[] a)
  19.             {
  20.                 int sum = 0;
  21.                 for(int tmp:a)
  22.                 {
  23.                         sum += tmp;
  24.                 }
  25.                 return sum;
  26.             }
  27.         });
  28.     }
  29. }

阅读(1522) | 评论(0) | 转发(0) |
0

上一篇:java单例类

下一篇:java Iterator

给主人留下些什么吧!~~