package?com.zt.test;
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比海北州網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式海北州網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋海北州地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
import?java.util.Stack;
public?class?Test7?{
private?StackString?box;
public?String?operationBox(boolean?flag,?String?num)?{
String?str?=?"";
synchronized?(Test7.class)?{
if?(flag)?{
this.box.push(num);
}?else?{
str?=?this.box.pop();
}
}
return?str;
}
public?static?void?main(String?args[])?{
Test7?a?=?new?Test7();
a.initApples();
}
public?Test7()?{
this.box?=?new?StackString();
}
public?void?forSleep(int?i)?{
try?{
Thread.sleep(i);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
/**
?*?放蘋果的人
?*/
public?void?putApple()?{
int?no?=?1;
while?(true)?{
this.forSleep(1000);
int?check?=?this.box.size();
System.out.println("---------現(xiàn)在有"?+?check?+?"個(gè)蘋果---------");
if?(check?=?5)?{
System.out.println("------------箱子里有5個(gè)蘋果無法放入------------");
continue;
}?else?{
System.out
.println("------------放入第"?+?no?+?"個(gè)蘋果--------------");
this.operationBox(true,?no?+?"");
no?=?no?+?1;
}
}
}
/**
?*?拿蘋果的人
?*/
public?void?getApple()?{
while?(true)?{
this.forSleep(800);
int?check?=?this.box.size();
System.out.println("=========現(xiàn)在有"?+?check?+?"個(gè)蘋果============");
if?(check?==?0)?{
System.out.println("==========箱子里有0個(gè)蘋果無法去除===========");
continue;
}?else?{
String?str?=?this.operationBox(false,?null);
System.out.println("==========從箱子出取出第"?+?str?+?"個(gè)蘋果==========");
}
}
}
/*
?*?初始化兩個(gè)人
?*/
public?void?initApples()?{
Thread?t1?=?new?Thread(new?Runnable()?{
public?void?run()?{
try?{
putApple();
}?catch?(Exception?e)?{
}
}
});
t1.start();
Thread?t2?=?new?Thread(new?Runnable()?{
public?void?run()?{
try?{
getApple();
}?catch?(Exception?e)?{
}
}
});
t2.start();
}
}
一個(gè)放一個(gè)拿,operationBox()鎖住stack的操作,forsleep方法是進(jìn)行休眠的,模擬一塊一慢,如果需要無序時(shí)間,自己寫隨機(jī)函數(shù)進(jìn)行線程休眠。
每次請(qǐng)求參數(shù)或者sql作為緩存key,如果key存在從緩存取,否則走數(shù)據(jù)庫,結(jié)果緩存.緩存框架選擇因業(yè)務(wù)而異
java代碼 30分 呵呵
這種的建議用htmlcleaner的類包解析
直接就是java對(duì)象
public class URLReader {
public String readResponseFromURL(String url) throws MalformedURLException, IOException {
// open reader for URL
InputStreamReader in = new InputStreamReader(new URL(url).openStream());
// read contents into string buffer
StringBuilder input = new StringBuilder();
int ch;
while ((ch = in.read()) != -1) {
input.append((char) ch);
}
return input.toString();
}
}
調(diào)用
URLReader reader = new URLReader();
String input = reader.readResponseFromURL(url);
TagNode node = htmlCleaner.clean(input);
這里node就是html的節(jié)點(diǎn)了
所有的都可以從里面取得
import javax.swing.JOptionPane;
public class Account
{
private String name;
private String account;
private String data;
private String ID;
private double balance;
public Account(String name,double balance,String data,String ID)
{
this.name = name;
this.balance = balance;
this.data=data;
this.ID=ID;
}
public String getaccount()
{
this.account=String.valueOf((int)(Math.random()*100000)+1);
return account;
}
public String getdata()
{
return data;
}
public String getID()
{
return ID;
}
public String getName()
{
return name;
}
public double getbalance()
{
return balance;
}
//查看賬戶余額
public double balance()
{
return balance;
}
//查看開戶時(shí)間
public String data()
{
return data;
}
//存款操作
public boolean put(double value)
{
if (value0)
{
this.balance += value;
return true;
}
return false;
}
//取款操作
public double get(double value)
{
if (value0)
{
if (value=this.balance)
this.balance -= value;
else
{
value = this.balance;
this.balance = 0;
}
return value;
}
return 0;
}
public static void main(String args[]){
Account user=new Account("張三",2000,"2011/05/23","362329198906234225");
String str;
int b;
String s=JOptionPane.showInputDialog("您好,存款選擇1,取款選擇2,退出選擇0");
int x=Integer.parseInt(s);
while(x!=0){
if(x==1)
{
str=JOptionPane.showInputDialog("輸入您要存入的數(shù)額");
b=Integer.parseInt(str);
if( user.put(b)){
JOptionPane.showMessageDialog(null, "請(qǐng)放入鈔票!");
JOptionPane.showMessageDialog(null,"開戶賬號(hào)為"+user.getaccount()+"\n"+user.getName()+"\n開戶時(shí)間為"+user.data()+"\n您的余額為"+user.balance());
}
else
JOptionPane.showMessageDialog(null, "你所輸入的存款數(shù)額有誤!");
}
else{
str=JOptionPane.showInputDialog("輸入您要取出的數(shù)額");
b=Integer.parseInt(str);
if(buser.balance())
{
JOptionPane.showMessageDialog(null, "余額不足");
}
else
{
JOptionPane.showMessageDialog(null, "請(qǐng)取出鈔票!");
user.get(b);
JOptionPane.showMessageDialog(null,"開戶賬號(hào)為"+user.getaccount()+"\n"+user.getName()+"\n開戶時(shí)間為"+user.data()+"\n您的余額為"+user.balance());
}
}
s=JOptionPane.showInputDialog("您好,存款選擇1,取款選擇2,退出選擇0");
x=Integer.parseInt(s);
}
}
}
當(dāng)前題目:java代碼實(shí)現(xiàn)取放 java怎么實(shí)現(xiàn)
標(biāo)題路徑:http://muchs.cn/article30/ddcgiso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、靜態(tài)網(wǎng)站、虛擬主機(jī)、網(wǎng)站設(shè)計(jì)公司、商城網(wǎng)站、用戶體驗(yàn)
聲明:本網(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)