十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
程序运行截图:
创新互联服务项目包括桂东网站建设、桂东网站制作、桂东网页制作以及桂东网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,桂东网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到桂东省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
1.单循环赛,是所有参加比赛的队均能相遇一次
2.运动员类Sportsman
3.运动项目类SportsEvents
4.运动场地类PlayingField
5.测试类
写了个简单的,不知道是不是你想要的,里面的main方法作了一个简单的测试。几个变量我定义为类变量。 public class PubTest {
private float fvar1, fvar2;
private int ivar1;
public PubTest(float fval1, float fval2, int ival) {
fvar1 = fval1;
fvar2 = fval2;
ivar1 = ival;
}
public PubTest() {
fvar1 = fvar2 = 0.0f;
ivar1 = 0;
}
public float getFvar1() {
return fvar1;
}
public float getFvar2() {
return fvar2;
}
public int getIvar1() {
return ivar1;
}
public void sum() {
fvar2 += fvar1;
}
public static void main(String[] args) {
PubTest pubTest = new PubTest(3.0f, 5.0f, 1);
pubTest.sum();
System.out.println(pubTest.getFvar2());
}
}
以前的!
====代码====
package com;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* 网球赛
* @author Cris
* @ClassName: Match
* @Version
* @ModifiedBy
* @Copyright @ 2010 HL Technology Inc.
* @date 2011-5-24 上午11:29:39
* @description
*/
public class Match implements ActionListener{
private JFrame f;
private JTextField tf;
private JPanel container;
private JList myList ;
private JLabel message;
private JButton b;
/**
* @author Cris
* @title: main
* @date 2011-5-23 上午11:07:27
* @param args void
*/
public static void main(String[] args) {
Match t = new Match();
t.go();
}
public void go(){
f = new JFrame("比赛");
f.setLocation(100, 200);
f.setSize(600,500);
container = new JPanel(new BorderLayout());
f.setContentPane(container);
JPanel title = new JPanel(new FlowLayout());
tf = new JTextField(10);
title.add(tf);
b = new JButton("确定");
b.addActionListener(this);
title.add(b);
message = new JLabel();
title.add(message);
container.add(title,BorderLayout.NORTH);
myList = new JList();
container.add(myList,BorderLayout.CENTER);
f.setVisible(true);
}
/**
* 显示比赛结果
* @author Cris
* @title: show
* @date 2011-5-24 上午11:31:05
* @param n void
*/
private void show(int n){
Cris c = new Cris(n);
ListListString[] result = c.getResult();
String[] str = new String[result.size()];
for (int i = 0; i result.size(); i++) {
StringBuilder sb = new StringBuilder();
sb.append("第").append(i+1).append("天: ");
ListString[] matchList = result.get(i);
for(String[] match : matchList){
sb.append("[").append(match[0]).append("-").append(match[1]).append("] ");
}
str[i] = sb.toString();
}
myList.setListData(str);
message.setText("");
f.setVisible(true);
}
/**
* 清空数据
* @author Cris
* @title: clear
* @date 2011-5-24 上午11:30:36 void
*/
private void clear(){
String[] str = {""};
myList.setListData(str);
message.setText("");
}
public void actionPerformed(ActionEvent e) {
clear();
String s = tf.getText();
if (s == null || "".equals(s = s.trim()) ) {
message.setText("请输入一个偶数");
}
try {
int n = Integer.parseInt(s);
if (n = 0 || n % 2 != 0) {
message.setText("请输入一个偶数");
}else{
show(n);
}
} catch (Exception ex) {
message.setText("请输入一个偶数");
}
f.setVisible(true);
}
}
第二个类:
package com;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class Cris {
/**选手数量*/
private int n ;
/**各个运动员还没进行的比赛 key:球员名称,value:需进行的比赛集合*/
private MapString, ListString[] playerMacth ;
/**球员人名*/
private String[] players ;
/**最终每天的比赛分布集合*/
private ListListString[] result;
/**所有可选的比赛*/
private ListListString[] allMatchData[];
/**每天的比赛*/
ListString[] dayMatch ;
/**一个随机对象*/
private Random r;
/**当前运算到的天数*/
private int nowDay;
public Cris(int n){
this.n = n;
playerMacth = new HashMapString, ListString[]();;
result = new ArrayListListString[]();
allMatchData = new LinkedList[n-1];
r = new Random();
init();
go();
}
/**
* 初始化球员
* @author Cris
* @title: init
* @date 2011-5-23 下午04:22:32 void
*/
private void init(){
//定义球员人名,以数字代表,从1开始
players = new String[n];
for (int i = 0; i players.length; i++) {
//定义球员的名字
players[i] = String.valueOf(i+1);
//存放每个球员要进行的比赛的集合
ListString[] matchList = new LinkedListString[]();
//球员赛事集合
playerMacth.put(players[i], matchList);
//球员集合,不变
// playerListConst.add(players[i]);
}
//定义每个人的比赛
for (int i = 0; i players.length -1; i++) {
for (int j = i+1; j players.length ; j++) {
String[] match = {players[i],players[j]};//定义一个比赛
//把此赛事添加到相应球员需比赛集合中
playerMacth.get(players[i]).add(match);
playerMacth.get(players[j]).add(match);
}
}
}
/**
* 随机获得一个当前天数可进行的比赛组合,并把此比赛组合从总集合中移除
* 如果当前天数无比赛,则先获得比赛,再随机
* @author Cris
* @title: getNowDayMatch
* @date 2011-5-24 上午09:48:23
* @return ListString[]
*/
private ListString[] getNowDayMatch(){
if (allMatchData[nowDay] == null) {
setAllMatchNowDay();
}
if (! allMatchData[nowDay].isEmpty()) {
int index = r.nextInt(allMatchData[nowDay].size());
ListString[] list = allMatchData[nowDay].get(index);
allMatchData[nowDay].remove(index);
return list;
}else {
return null;
}
}
/**
* 取消前一天的比赛
* @author Cris
* @title: cancelYesterday
* @date 2011-5-24 上午09:56:12 void
*/
private void cancelYesterday(){
//清空当前天数的可选比赛组合
allMatchData[nowDay] = null ;
//时间恢复到前一天
nowDay--;
//获得前一天的比赛
ListString[] matchList = result.get(nowDay);
//取消前一天的比赛
result.remove(nowDay);
//恢复每个运动员未进行的比赛
for(String[] match : matchList){
playerMacth.get(match[0]).add(match);
playerMacth.get(match[1]).add(match);
}
}
public void go(){
//循环比赛天数
for ( nowDay = 0; nowDay n -1; ) {
//1.随机一个比赛
ListString[] matchList = getNowDayMatch();
//无比赛组合 ,返回上一天 取消上一天的比赛,时间回退到前一天,跳过此次循环
if (matchList == null) {
cancelYesterday();
continue;
}
//3遍历比赛 去除运动员 去除运动员的未进行比赛
for(String[] match : matchList){
playerMacth.get(match[0]).remove(match);
playerMacth.get(match[1]).remove(match);
}
result.add(matchList);
nowDay++;
}
}
/**
* 从1号队员开始,获得当前天数所有可组合的赛事
* @author Cris
* @title: setAllMatchNowDay
* @date 2011-5-24 上午09:42:51 void
*/
private void setAllMatchNowDay(){
allMatchData[nowDay] = new LinkedListListString[]();
int n = 1;//1号运动员
//此运动员未进行的比赛
ListString[] matchList = playerMacth.get(String.valueOf(n));
for(String[] match : matchList){
ListString[] selectedList = new ArrayListString[]();
selectedList.add(match);
doDetAllMatchNowDay(n+1, selectedList);
}
}
/**
* 今天比赛的所有组合
* @author Cris
* @title: doDetAllMatchNowDay
* @date 2011-5-24 上午09:46:05
* @param playerNum
* @param selectedList void
*/
private void doDetAllMatchNowDay(int playerNum,ListString[] selectedList){
//运动员名称
String player = String.valueOf(playerNum);
boolean flag = true;
//判断此运动员是不是已被选过
for(String[] match : selectedList){
if (match[0].equals(player) || match[1].equals(player)) {
flag = false;
break;
}
}
//已被选过
if ( flag == false) {
//最后一个人员
if (playerNum == n) {
allMatchData[nowDay].add(selectedList);
}else{
doDetAllMatchNowDay(playerNum+1, selectedList);
}
return;
}
//此运动员未进行的比赛
ListString[] matchList = playerMacth.get(player);
//此运动员可选择的比赛
ListString[] canDoList = new ArrayListString[]();
for(String[] match : matchList){
flag = true;
for(String[] selected : selectedList){
if(match[0].equals(player)){
if(match[1].equals(selected[0])){
flag = false;
}else if(match[1].equals(selected[1])){
flag = false;
}
}else{
if(match[0].equals(selected[0])){
flag = false;
}else if(match[0].equals(selected[1])){
flag = false;
}
}
}
if (flag) {
canDoList.add(match);
}
}
//遍历此运动员可选择的比赛
for(String[] match : canDoList){
ListString[] newList = copyArrayList(selectedList);
//记录当前比赛
newList.add(match);
//最后一个人员
if (playerNum == n) {
allMatchData[nowDay].add(newList);
}else{
doDetAllMatchNowDay(playerNum+1, newList);
}
}
}
/**
* 复制集合
* @author Cris
* @title: copyArrayList
* @date 2011-5-24 上午09:24:44
* @param list
* @return ListString[]
*/
private ListString[] copyArrayList(ListString[] list){
ListString[] newList = new ArrayListString[]();
for(String[] s : list){
newList.add(s);
}
return newList;
}
public ListListString[] getResult() {
return result;
}
}
public class Main {
public static void main(String[] args) {
int i = 1;
int result = 0;
while(i10){
result += i;
i++;
}
System.out.println("1+2+3+4+5+6+7+8+9="+result);
}
}
md5加密:
package com.ncs.pki.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Test {
private static MessageDigest digest = null;
public synchronized static final String hash(String data) {
if (digest == null) {
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsae) {
System.err.println(
"Failed to load the MD5 MessageDigest. "
+ "Jive will be unable to function normally.");
nsae.printStackTrace();
}
}
// Now, compute hash.
digest.update(data.getBytes());
return encodeHex(digest.digest());
}
public static final String encodeHex(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
int i;
for (i = 0; i bytes.length; i++) {
if (((int) bytes[i] 0xff) 0x10) {
buf.append("0");
}
buf.append(Long.toString((int) bytes[i] 0xff, 16));
}
return buf.toString();
}
public static String test(){
return null;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(MD5Test.hash("123456"));
}
}
3des加密:
package com.ncs.pki.util;
import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DesEncrypt {
/**
*
* 使用DES加密与解密,可对byte[],String类型进行加密与解密 密文可使用String,byte[]存储.
*
* 方法: void getKey(String strKey)从strKey的字条生成一个Key
*
* String getEncString(String strMing)对strMing进行加密,返回String密文 String
* getDesString(String strMi)对strMin进行解密,返回String明文
*
*byte[] getEncCode(byte[] byteS)byte[]型的加密 byte[] getDesCode(byte[]
* byteD)byte[]型的解密
*/
Key key;
/**
* 根据参数生成KEY
*
* @param strKey
*/
public void getKey(String strKey) {
try {
KeyGenerator _generator = KeyGenerator.getInstance("DES");
_generator.init(new SecureRandom(strKey.getBytes()));
this.key = _generator.generateKey();
_generator = null;
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 加密String明文输入,String密文输出
*
* @param strMing
* @return
*/
public String getEncString(String strMing) {
byte[] byteMi = null;
byte[] byteMing = null;
String strMi = "";
BASE64Encoder base64en = new BASE64Encoder();
try {
byteMing = strMing.getBytes("UTF8");
byteMi = this.getEncCode(byteMing);
strMi = base64en.encode(byteMi);
} catch (Exception e) {
e.printStackTrace();
} finally {
base64en = null;
byteMing = null;
byteMi = null;
}
return strMi;
}
/**
* 解密 以String密文输入,String明文输出
*
* @param strMi
* @return
*/
public String getDesString(String strMi) {
BASE64Decoder base64De = new BASE64Decoder();
byte[] byteMing = null;
byte[] byteMi = null;
String strMing = "";
try {
byteMi = base64De.decodeBuffer(strMi);
byteMing = this.getDesCode(byteMi);
strMing = new String(byteMing, "UTF8");
} catch (Exception e) {
e.printStackTrace();
} finally {
base64De = null;
byteMing = null;
byteMi = null;
}
return strMing;
}
/**
* 加密以byte[]明文输入,byte[]密文输出
*
* @param byteS
* @return
*/
private byte[] getEncCode(byte[] byteS) {
byte[] byteFina = null;
Cipher cipher;
try {
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byteFina = cipher.doFinal(byteS);
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return byteFina;
}
/**
* 解密以byte[]密文输入,以byte[]明文输出
*
* @param byteD
* @return
*/
private byte[] getDesCode(byte[] byteD) {
Cipher cipher;
byte[] byteFina = null;
try {
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byteFina = cipher.doFinal(byteD);
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return byteFina;
}
public static void main(String[] args) {
System.out.println("des demo");
DesEncrypt des = new DesEncrypt();// 实例化一个对像
des.getKey("MYKEY");// 生成密匙
System.out.println("key=MYKEY");
String strEnc = des.getEncString("111111");// 加密字符串,返回String的密文
System.out.println("密文=" + strEnc);
String strDes = des.getDesString(strEnc);// 把String 类型的密文解密
System.out.println("明文=" + strDes);
}
}
java在代码中加一些无用代码的方法:
1、压缩(Shrink)检测并移除代码中无用的类、字段、方法和特性(Attribute)。
2、优化(Optimize)对字节码进行优化,移除无用的指令。优化代码,非入口节点类会加上private/static/final,没有用到的参数会被删除,一些方法可能会变成内联代码。