点赞游戏,自己编的
答案:5 悬赏:10 手机版
解决时间 2021-03-12 08:07
- 提问者网友:孤凫
- 2021-03-12 05:13
点赞游戏,自己编的
最佳答案
- 五星知识达人网友:人類模型
- 2021-03-12 06:08
public class Cc {
public static void main(String[] args) {
// TODO Auto-generated method stub
School xuexiao = new School();
xuexiao.setMoney(0);
Thread acc,teacher;
acc = new Thread(xuexiao);
teacher = new Thread(xuexiao);
acc.setName("学校");
teacher.setName("老师");
acc.start();
teacher.start();
}
}
public class School implements Runnable {
int money=0;
public void setMoney(int n) {
money=n;
}
public void run(){
if(Thread.currentThread().getName().equals("学校"))
saveOrTake(1000);
else if(Thread.currentThread().getName().equals("老师"))
saveOrTake(1000);
}
public synchronized void saveOrTake (int amount) {
if(Thread.currentThread().getName().equals("学校")){
for(int i=1;i<=3;i++) {
money=money+amount/3;
System.out.println(Thread.currentThread().getName()+"存入"+amount/3+",账上有"+money+"万,");
try { Thread.sleep(1000);
}
catch(InterruptedException e){
}
}
}
else if(Thread.currentThread().getName().equals("老师")) {
for(int i=1;i<=3;i++) {
money=money-amount/3;
System.out.println(Thread.currentThread().getName()+"取出"+amount/3+",账上有"+money+"万,");
try { Thread.sleep(1000);
}
catch(InterruptedException e){}
}
}
}
}
import java.util.*;
public class dui_zhan {
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack stack = new Stack();
stack.push(new Integer(1));
stack.push(new Integer(1));
for(int i=1;i<=10;i++) {
Integer F1=stack.pop();
int f1=F1.intValue();
Integer F2=stack.pop();
int f2=F2.intValue();
Integer temp=new Integer(f1+f2);
System.out.println(""+temp.toString());
stack.push(temp);
stack.push(f2);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
School xuexiao = new School();
xuexiao.setMoney(0);
Thread acc,teacher;
acc = new Thread(xuexiao);
teacher = new Thread(xuexiao);
acc.setName("学校");
teacher.setName("老师");
acc.start();
teacher.start();
}
}
public class School implements Runnable {
int money=0;
public void setMoney(int n) {
money=n;
}
public void run(){
if(Thread.currentThread().getName().equals("学校"))
saveOrTake(1000);
else if(Thread.currentThread().getName().equals("老师"))
saveOrTake(1000);
}
public synchronized void saveOrTake (int amount) {
if(Thread.currentThread().getName().equals("学校")){
for(int i=1;i<=3;i++) {
money=money+amount/3;
System.out.println(Thread.currentThread().getName()+"存入"+amount/3+",账上有"+money+"万,");
try { Thread.sleep(1000);
}
catch(InterruptedException e){
}
}
}
else if(Thread.currentThread().getName().equals("老师")) {
for(int i=1;i<=3;i++) {
money=money-amount/3;
System.out.println(Thread.currentThread().getName()+"取出"+amount/3+",账上有"+money+"万,");
try { Thread.sleep(1000);
}
catch(InterruptedException e){}
}
}
}
}
import java.util.*;
public class dui_zhan {
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack
stack.push(new Integer(1));
stack.push(new Integer(1));
for(int i=1;i<=10;i++) {
Integer F1=stack.pop();
int f1=F1.intValue();
Integer F2=stack.pop();
int f2=F2.intValue();
Integer temp=new Integer(f1+f2);
System.out.println(""+temp.toString());
stack.push(temp);
stack.push(f2);
}
}
}
全部回答
- 1楼网友:上分大魔王
- 2021-03-12 10:19
好,点赞!
- 2楼网友:夜余生
- 2021-03-12 10:10
有
- 3楼网友:持酒劝斜阳
- 2021-03-12 08:47
点赞游戏?!这什么玩意儿
- 4楼网友:独行浪子会拥风
- 2021-03-12 07:28
上头条~~~~~~~~~~~~~~~~~~~~
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯