老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

分蘋果的java代碼 java蘋果好吃

求Java代碼

package?com.zhuq;

澄城ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為創新互聯建站的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

public?class?Apple?extends?Fruit{

@Override

public?void?eat()?{

System.out.println("吃蘋果");

}

@Override

public?void?shape()?{

System.out.println("蘋果形狀");

}

}

class?Banana?extends?Fruit{

@Override

public?void?eat()?{

System.out.println("吃香蕉");

}

@Override

public?void?shape()?{

System.out.println("香蕉形狀");

}

}

class?Orange?extends?Fruit{

@Override

public?void?eat()?{

System.out.println("吃橘子");

}

@Override

public?void?shape()?{

System.out.println("橘子形狀");

}

}

abstract?class?Fruit{

abstract?void?eat();

abstract?void?shape();

public?void?String(){

this.eat();

this.shape();

}

}

/**??*/

public?class?Game?{

public?static?Fruit?中獎(){

Integer?i?=(int)?(Math.random()*3);

Fruit?f=null;

switch?(i){

case?0:?f=new?Apple();break;

case?1:?f=new?Banana();break;

case?2:f=new?Orange();break;

}

return?f;

}

}

/**??*/

public?class?Zhuq{

public?static?void?main(String[]?args)?{

Fruit[]?fruits?=?{null,null,null,null,null,null,null,null,null,null}?;

for(int?m=0;m10;m++){

fruits[m]?=Game.中獎();

}

for?(int?i?=?0;?i??fruits.length;?i++)?{

fruits[i].String();

}

}

}

java程序題:定義一個抽象類-水果,其中包括getWeight()方法,編寫程序分別創建蘋果、

水果類

abstract?public?class?Fruit?{

abstract?public?double?getWeight();

}

蘋果類

public?class?Apple?extends?Fruit?{

private?double?weight;

public?Apple(double?weight)?{

this.weight?=?weight;

}

@Override

public?double?getWeight()?{

return?weight;

}

}

橘子類

public?class?Orange?extends?Fruit?{

private?double?weight;

public?Orange(double?weight)?{

this.weight?=?weight;

}

@Override

public?double?getWeight()?{

return?weight;

}

}

桃子類

public?class?Peach?extends?Fruit?{

private?double?weight;

public?Peach(double?weight)?{

this.weight?=?weight;

}

@Override

public?double?getWeight()?{

return?weight;

}

}

主類

public?class?Main?{

public?static?void?main(String[]?args)?{

//?TODO?Auto-generated?method?stub

Fruit[]?fruits?=?{?new?Peach(12),?new?Apple(2),?new?Orange(5)?};

for?(Fruit?fruit?:?fruits)?{

System.out.println(fruit.getClass().getName()?+?"的重量是"

+?fruit.getWeight());

}

}

}

運行結果

Peach的重量是 12.0

Apple的重量是 2.0

Orange的重量是 5.0

5種水果,用java來按照字典順序排列輸出

public class Fruit {

String[] fruits=new String[5];

public void inputfruit(){

Scanner input=new Scanner(System.in);

for(int i=0;ifruits.length;i++){

System.out.print("請輸入第"+(i+1)+"種水果:");

fruits[i]=input.next();

}

}

public String[] getNames(){

Arrays.sort(fruits);

return fruits;

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

Fruit sg=new Fruit();

String[] newFruits=new String[5];

sg.inputfruit();

newFruits=sg.getNames();

System.out.println("這些水果在字典種出現的順序是:");

for(int i=0;inewFruits.length;i++){

if(newFruits[i]!=null){

System.out.print(newFruits[i]+"\t");

}

}

}

java算法,例子N個蘋果放到20個袋子中,操作時間為4個小時,其中每個袋子的各蘋果放入時間間隙大于30分鐘

需要使用多線程

package org.xuyh.design;

import java.util.Scanner;

/**

* N個蘋果放到20個袋子中,操作時間為4個小時,其中每個袋子的各蘋果放入時間間隙大于30分鐘

* @author XuYanhang

*

*/

public class AppleOperation implements Runnable{

public static final int ONE_SECOND = 1000;

private final int[] packages;

public final int operationTime;

public final int minSpacetTime;

private int appleCount;

private boolean timeEnd = false;

public AppleOperation(int appleCount,int packCount,int operationTime,int minSpacetTime){

this.appleCount = appleCount;

packages = new int[packCount];

this.operationTime = operationTime;

this.minSpacetTime = minSpacetTime;

}

public int getAppleCount(){

return appleCount;

}

public int getPackCount(){

return packages.length;

}

public int getOperationTime(){

return operationTime;

}

public boolean hasEnd(){

return timeEnd || appleCount == 0;

}

public synchronized void setTimeEnd(){

timeEnd = true;

}

public void run() {

int pack = Integer.parseInt(Thread.currentThread().getName());

while(appleCount0){

synchronized(this){

if(hasEnd()){

break;

}

appleCount--;

packages[pack]++;

System.out.println("一個蘋果放入了第"+(pack+1)+"個袋子中,還剩"+appleCount+"個蘋果");

}

for(int i = 0 ; i minSpacetTime ; i++){

synchronized(this){

if(hasEnd()){

break;

}

}

try {

Thread.sleep(ONE_SECOND);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

synchronized(this){

System.out.println("第"+(pack+1)+"個袋子最終有"+packages[pack]+"個蘋果");

}

}

//Test main method

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int appleCount = -1;

do{

System.out.print("N個蘋果放到20個袋子中,操作時間為4個小時,其中每個袋子的各蘋果放入時間間隙大于30分鐘。\n"

+ "輸入蘋果總數N:");

String string = scanner.next();

if(null != string string.matches("^\\d{1,8}$")){

appleCount = Integer.parseInt(string);

}

}while(appleCount == -1);

scanner.close();

AppleOperation operation = new AppleOperation(appleCount,20,4*60*60,30*60);

new WaitThread(operation).start();

for (int i = 0; i operation.getPackCount(); i++) {

Thread thread = new Thread(operation,""+i);

thread.start();

}

}

static class WaitThread extends Thread{

private AppleOperation operation;

public WaitThread(AppleOperation operation){

this.operation = operation;

}

public void run(){

try {

Thread.sleep(operation.getOperationTime()*ONE_SECOND);

} catch (InterruptedException e) {

e.printStackTrace();

}

operation.setTimeEnd();

System.out.println("時間到,蘋果裝袋操作結束,最后為裝袋的蘋果個數:"+operation.getAppleCount());

}

}

}

這里我們額外啟動了21個線程,其中一個是計4小時的定時的,其他20個是向每個袋子中放蘋果的線程。


網站名稱:分蘋果的java代碼 java蘋果好吃
網頁網址:http://www.xueling.net.cn/article/dddepdi.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 国产特色特黄的视频免费观看 | 亚洲精品久久久久久久蜜桃 | AV换脸明星一区二区三区 | 日韩精品成人一区二区在线 | 免费观看高清a级毛片视频 成人精品天堂一区二区三区 | 久久不见久久见免费影院视频观看 | 每日更新av在线播放 | 国产熟妇勾子乱视频 | 中文字幕日韩av | 久久久国产AV | 天天天天天天天天操 | 成人免费视频一区 | 免费在线观看h视频 | 妺妺窝人体色WWW看美女 | 一个人免费观看的WWW视频 | 午夜在线视频观看 | 亚洲sss视频在线视频 | 性感一级毛片 | 免费无码一区二区三区A片 未满小14洗澡无码视频网站 | 大桥未久亚洲精品久久久强制中出 | 四虎影视永久在线观看 | 日本三级在线观看视频 | 男男暴菊gay无套网站 | 中文无码精品a∨在线 | 国产精品久久一区性色av图片 | 免费国产小视频 | 亚洲AV无码成人影片在线观看 | 亚洲一区美女 | 国产一区二区在线免费播放 | 日韩中文字幕久久 | 日韩一级片一区二区三区 | 性少妇xxxxx| 波多野结衣在线视频一区二区三区 | 成人免费午夜视频69影院 | 91韩国| 国内久久 | 久久精品蜜臀 | 麻豆aⅴ精品无码一区二区 亚洲大尺度专区无码浪潮AV | 无码AV一级毛片在线播放 | 无码人妻AⅤ一区二区三区麻豆 | 欧美1区视频|