程序運(yùn)行截圖:

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括桂東網(wǎng)站建設(shè)、桂東網(wǎng)站制作、桂東網(wǎng)頁制作以及桂東網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,桂東網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到桂東省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
1.單循環(huán)賽,是所有參加比賽的隊(duì)均能相遇一次
2.運(yùn)動(dòng)員類Sportsman
3.運(yùn)動(dòng)項(xiàng)目類SportsEvents
4.運(yùn)動(dòng)場(chǎng)地類PlayingField
5.測(cè)試類
寫了個(gè)簡(jiǎn)單的,不知道是不是你想要的,里面的main方法作了一個(gè)簡(jiǎn)單的測(cè)試。幾個(gè)變量我定義為類變量。 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;
/**
* 網(wǎng)球賽
* @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);
}
/**
* 顯示比賽結(jié)果
* @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);
}
/**
* 清空數(shù)據(jù)
* @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("請(qǐng)輸入一個(gè)偶數(shù)");
}
try {
int n = Integer.parseInt(s);
if (n = 0 || n % 2 != 0) {
message.setText("請(qǐng)輸入一個(gè)偶數(shù)");
}else{
show(n);
}
} catch (Exception ex) {
message.setText("請(qǐng)輸入一個(gè)偶數(shù)");
}
f.setVisible(true);
}
}
第二個(gè)類:
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 {
/**選手?jǐn)?shù)量*/
private int n ;
/**各個(gè)運(yùn)動(dòng)員還沒進(jìn)行的比賽 key:球員名稱,value:需進(jìn)行的比賽集合*/
private MapString, ListString[] playerMacth ;
/**球員人名*/
private String[] players ;
/**最終每天的比賽分布集合*/
private ListListString[] result;
/**所有可選的比賽*/
private ListListString[] allMatchData[];
/**每天的比賽*/
ListString[] dayMatch ;
/**一個(gè)隨機(jī)對(duì)象*/
private Random r;
/**當(dāng)前運(yùn)算到的天數(shù)*/
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(){
//定義球員人名,以數(shù)字代表,從1開始
players = new String[n];
for (int i = 0; i players.length; i++) {
//定義球員的名字
players[i] = String.valueOf(i+1);
//存放每個(gè)球員要進(jìn)行的比賽的集合
ListString[] matchList = new LinkedListString[]();
//球員賽事集合
playerMacth.put(players[i], matchList);
//球員集合,不變
// playerListConst.add(players[i]);
}
//定義每個(gè)人的比賽
for (int i = 0; i players.length -1; i++) {
for (int j = i+1; j players.length ; j++) {
String[] match = {players[i],players[j]};//定義一個(gè)比賽
//把此賽事添加到相應(yīng)球員需比賽集合中
playerMacth.get(players[i]).add(match);
playerMacth.get(players[j]).add(match);
}
}
}
/**
* 隨機(jī)獲得一個(gè)當(dāng)前天數(shù)可進(jìn)行的比賽組合,并把此比賽組合從總集合中移除
* 如果當(dāng)前天數(shù)無比賽,則先獲得比賽,再隨機(jī)
* @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(){
//清空當(dāng)前天數(shù)的可選比賽組合
allMatchData[nowDay] = null ;
//時(shí)間恢復(fù)到前一天
nowDay--;
//獲得前一天的比賽
ListString[] matchList = result.get(nowDay);
//取消前一天的比賽
result.remove(nowDay);
//恢復(fù)每個(gè)運(yùn)動(dòng)員未進(jìn)行的比賽
for(String[] match : matchList){
playerMacth.get(match[0]).add(match);
playerMacth.get(match[1]).add(match);
}
}
public void go(){
//循環(huán)比賽天數(shù)
for ( nowDay = 0; nowDay n -1; ) {
//1.隨機(jī)一個(gè)比賽
ListString[] matchList = getNowDayMatch();
//無比賽組合 ,返回上一天 取消上一天的比賽,時(shí)間回退到前一天,跳過此次循環(huán)
if (matchList == null) {
cancelYesterday();
continue;
}
//3遍歷比賽 去除運(yùn)動(dòng)員 去除運(yùn)動(dòng)員的未進(jìn)行比賽
for(String[] match : matchList){
playerMacth.get(match[0]).remove(match);
playerMacth.get(match[1]).remove(match);
}
result.add(matchList);
nowDay++;
}
}
/**
* 從1號(hào)隊(duì)員開始,獲得當(dāng)前天數(shù)所有可組合的賽事
* @author Cris
* @title: setAllMatchNowDay
* @date 2011-5-24 上午09:42:51 void
*/
private void setAllMatchNowDay(){
allMatchData[nowDay] = new LinkedListListString[]();
int n = 1;//1號(hào)運(yùn)動(dòng)員
//此運(yùn)動(dòng)員未進(jìn)行的比賽
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){
//運(yùn)動(dòng)員名稱
String player = String.valueOf(playerNum);
boolean flag = true;
//判斷此運(yùn)動(dòng)員是不是已被選過
for(String[] match : selectedList){
if (match[0].equals(player) || match[1].equals(player)) {
flag = false;
break;
}
}
//已被選過
if ( flag == false) {
//最后一個(gè)人員
if (playerNum == n) {
allMatchData[nowDay].add(selectedList);
}else{
doDetAllMatchNowDay(playerNum+1, selectedList);
}
return;
}
//此運(yùn)動(dòng)員未進(jìn)行的比賽
ListString[] matchList = playerMacth.get(player);
//此運(yùn)動(dòng)員可選擇的比賽
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);
}
}
//遍歷此運(yùn)動(dòng)員可選擇的比賽
for(String[] match : canDoList){
ListString[] newList = copyArrayList(selectedList);
//記錄當(dāng)前比賽
newList.add(match);
//最后一個(gè)人員
if (playerNum == n) {
allMatchData[nowDay].add(newList);
}else{
doDetAllMatchNowDay(playerNum+1, newList);
}
}
}
/**
* 復(fù)制集合
* @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加密與解密,可對(duì)byte[],String類型進(jìn)行加密與解密 密文可使用String,byte[]存儲(chǔ).
*
* 方法: void getKey(String strKey)從strKey的字條生成一個(gè)Key
*
* String getEncString(String strMing)對(duì)strMing進(jìn)行加密,返回String密文 String
* getDesString(String strMi)對(duì)strMin進(jìn)行解密,返回String明文
*
*byte[] getEncCode(byte[] byteS)byte[]型的加密 byte[] getDesCode(byte[]
* byteD)byte[]型的解密
*/
Key key;
/**
* 根據(jù)參數(shù)生成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();// 實(shí)例化一個(gè)對(duì)像
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)檢測(cè)并移除代碼中無用的類、字段、方法和特性(Attribute)。
2、優(yōu)化(Optimize)對(duì)字節(jié)碼進(jìn)行優(yōu)化,移除無用的指令。優(yōu)化代碼,非入口節(jié)點(diǎn)類會(huì)加上private/static/final,沒有用到的參數(shù)會(huì)被刪除,一些方法可能會(huì)變成內(nèi)聯(lián)代碼。
新聞名稱:java加賽代碼,賽碼網(wǎng)java輸入
瀏覽路徑:http://chinadenli.net/article24/dsghdce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、動(dòng)態(tài)網(wǎng)站、電子商務(wù)、做網(wǎng)站、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)