import java.util.*;

class Main {
	public static void main(String[] args) { 
        // LinkedList 实现了 Queue 接口
        LinkedList<Integer> list = new LinkedList<Integer>();

        for(int i =0;i<300;i++){
            list.add(i);
        }
        int size=list.size();
        //只保留200个, 将其他数据按先进先出的规则弹出
        if (list.size() > 200) {  
            for (int i = size ; i >200; i--) {
                list.poll();
             }
        }
        for (int i = 0 ; i <200; i++) {   
		    System.out.print(list.get(i)+",");
        }
	}
}
lohiecan(程独秀) - 2020-07-10 0 人
java Queue 应用,先进先出用法实例, ...
class Main {
	public static void main(String[] args) {
        int i=1;
        int j=i++;      //j=1, i=2
        System.out.println("i="+i);
        System.out.println("j="+j);

/*
    i++
        先运算再自加1
    ++i
        先自加1再运算
*/

        if((i==(++j))/* i=2, j=2 */&&(i++)==j)/* i=3, j=2 */{ 
        
            System.out.println("-----------------");
            System.out.println("i="+i);
            System.out.println("j="+j);
            i+=j;
        }

        System.out.println("-----------------");
        System.out.println("i="+i);
        System.out.println("j="+j);  
	}
}
owo24352(๛ก(ー̀ωー́ก)) - 2020-07-04 0 人
Java初级测试题目(1)
package data.scripts.hullmods;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.SettingsAPI;
import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.combat.ShipHullSpecAPI;
import com.fs.starfarer.api.combat.ShipSystemAPI;
import com.fs.starfarer.api.combat.ShipVariantAPI;
import com.fs.starfarer.api.graphics.SpriteAPI;
import com.fs.starfarer.api.ui.Alignment;
import com.fs.starfarer.api.ui.LabelAPI;
import com.fs.starfarer.api.ui.TooltipMakerAPI;
import com.fs.starfarer.api.util.Misc;
import data.scripts.util.II_Util;
import java.awt.Color;
import java.util.Collection;
import org.dark.shaders.util.ShaderLib;

public abstract class II_BasePackage extends BaseHullMod
{
  public static final String ARMOR_PACKAGE = "ii_armor_package";
  public static final String TARGETING_PACKAGE = "ii_targeting_package";
  public static final String ELITE_PACKAGE = "ii_elite_package";
  public static final String NO_PACKAGE = "ii_no_package";
  public static final String SWP_NO_PACKAGE = "swp_no_package";
  protected static final float PARA_PAD = 10.0F;
  protected static final float SECTION_PAD = 10.0F;
  protected static final float INTERNAL_PAD = 4.0F;
  protected static final float INTERNAL_PARA_PAD = 4.0F;
  protected static final float BULLET_PAD = 3.0F;
  private static final String ALT_SPRITES = "ii_alt_sprites";

  protected abstract String getHullModId();

  protected abstract String getAltSpriteSuffix();

  protected abstract void updateDecoWeapons(ShipAPI paramShipAPI);

  public void applyEffectsAfterShipCreation(ShipAPI ship, String id)
  {
    if (getAltSpriteSuffix() != null) { String spriteId = ship.getHullSpec().getBaseHullId() + getAltSpriteSuffix();
      SpriteAPI sprite;
      SpriteAPI sprite;
      try {
        sprite = Global.getSettings().getSprite("ii_alt_sprites", spriteId, false);
      } catch (RuntimeException ex) {
        sprite = null;
      }

      if (sprite != null) {
        float x = ship.getSpriteAPI().getCenterX();
        float y = ship.getSpriteAPI().getCenterY();
        float alpha = ship.getSpriteAPI().getAlphaMult();
        float angle = ship.getSpriteAPI().getAngle();
        Color color = ship.getSpriteAPI().getColor();

        ship.setSprite("ii_alt_sprites", spriteId);
        ShaderLib.overrideShipTexture(ship, spriteId);

        ship.getSpriteAPI().setCenter(x, y);
        ship.getSpriteAPI().setAlphaMult(alpha);
        ship.getSpriteAPI().setAngle(angle);
        ship.getSpriteAPI().setColor(color);
      } }


    updateDecoWeapons(ship);
  }

  public void advanceInCombat(ShipAPI ship, float amount)
  {
    updateDecoWeapons(ship);
  }

  protected abstract String getFlavorText();

  private void makeEmptySysModPostDescription(TooltipMakerAPI tooltip) {
    LabelAPI desc = tooltip.addPara("在安装后将会改变以下战术系统。", 4.0F, 
      Global.getSettings().getColor("standardTextColor"), new String[0]);
    addEmptySysModText(tooltip);
  }

  protected abstract void addEmptySysModText(TooltipMakerAPI paramTooltipMakerAPI);

  private void makeEmptyMiscModPostDescription(TooltipMakerAPI tooltip) {
    LabelAPI desc = tooltip.addPara("在安装后将会改变以下舰船性能。", 4.0F, 
      Global.getSettings().getColor("standardTextColor"), new String[0]);
    addEmptyMiscModText(tooltip);
  }

  protected abstract void addEmptyMiscModText(TooltipMakerAPI paramTooltipMakerAPI);

  private void makeImperialFlaresPostDescription(TooltipMakerAPI tooltip) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/flare_launcher.png", 64.0F);
    addImperialFlaresSysModText(text);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addImperialFlaresSysModText(TooltipMakerAPI paramTooltipMakerAPI);

  private void makeMicroForgePostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/missile_autoforge.png", 64.0F);
    addMicroForgeSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addMicroForgeSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeTurbofeederPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/ammo_feeder.png", 64.0F);
    addTurbofeederSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addTurbofeederSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeImpulseBoosterPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/infernium_injector.png", 64.0F);
    addImpulseBoosterSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addImpulseBoosterSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeOverdrivePostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/maneuvering_jets.png", 64.0F);
    addOverdriveSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addOverdriveSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeMagnumSalvoPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/missile_racks.png", 64.0F);
    addMagnumSalvoSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addMagnumSalvoSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeCommandCenterPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/reserve_deployment.png", 64.0F);
    addCommandCenterSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addCommandCenterSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeShockBusterPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/quantum_disruptor.png", 64.0F);
    addShockBusterSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addShockBusterSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeCelerityDrivePostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/temporal_shell.png", 64.0F);
    addCelerityDriveSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addCelerityDriveSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeLuxFinisPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/hullsys/high_energy_focus.png", 64.0F);
    addLuxFinisSysModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addLuxFinisSysModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeCargoPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/skills/fleet_logistics.png", 64.0F);
    addCargoMiscModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addCargoMiscModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeLightspearPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/skills/applied_physics.png", 64.0F);
    addLightspearMiscModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addLightspearMiscModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  private void makeTitanPostDescription(TooltipMakerAPI tooltip, ShipAPI ship) {
    TooltipMakerAPI text = tooltip.beginImageWithText("graphics/icons/skills/missile_specialization.png", 64.0F);
    addTitanMiscModText(text, ship);
    tooltip.addImageWithText(4.0F);
  }

  protected abstract void addTitanMiscModText(TooltipMakerAPI paramTooltipMakerAPI, ShipAPI paramShipAPI);

  protected void addCompatibilityStatement(TooltipMakerAPI tooltip) {
    LabelAPI label = tooltip.addPara("只能安装在 星际帝国 舰船上 且只能安装一种 帝国强化套件。", 10.0F);
    label.setHighlightColors(new Color[] { Global.getSettings().getDesignTypeColor("星际帝国"), Global.getSettings().getDesignTypeColor("星际帝国") });
    label.setHighlight(new String[] { "星际帝国", "帝国强化套件" });
  }

  protected abstract void addPrimaryDescription(TooltipMakerAPI paramTooltipMakerAPI);

  public void addPostDescriptionSection(TooltipMakerAPI tooltip, ShipAPI.HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec)
  {
    addPrimaryDescription(tooltip);

    if (getHullModId().contentEquals("ii_no_package")) {
      LabelAPI label = tooltip.addPara("该舰无法安装 帝国强化套件", 0.0F);
      label.setHighlightColors(new Color[] { Global.getSettings().getDesignTypeColor("星际帝国") });
      label.setHighlight(new String[] { "帝国强化套件" });

      if (getFlavorText() != null) {
        label = tooltip.addPara(getFlavorText(), Misc.getGrayColor(), 10.0F);
        label.setAlignment(Alignment.MID);
      }
    } else {
      addCompatibilityStatement(tooltip);

      if (getFlavorText() != null) {
        LabelAPI label = tooltip.addPara(getFlavorText(), Misc.getGrayColor(), 10.0F);
        label.setAlignment(Alignment.MID);
      }

      LabelAPI heading = tooltip.addSectionHeading("战术系统强化", 
        Global.getSettings().getColor("tooltipTitleAndLightHighlightColor"), Global.getSettings().getColor("buttonBgDark"), Alignment.TMID, 10.0F);

      if ((isForModSpec) || (ship == null) || (ship.getSystem() == null)) {
        makeEmptySysModPostDescription(tooltip);
      } else {
        String shipSystemId = ship.getSystem().getId();
        switch (shipSystemId)
        {
        case "ii_flares":
          makeImperialFlaresPostDescription(tooltip);
          break;
        case "ii_microforge":
          makeMicroForgePostDescription(tooltip, ship);
          break;
        case "ii_turbofeeder":
          makeTurbofeederPostDescription(tooltip, ship);
          break;
        case "ii_impulsebooster":
          makeImpulseBoosterPostDescription(tooltip, ship);
          break;
        case "ii_overdrive":
          makeOverdrivePostDescription(tooltip, ship);
          break;
        case "ii_magnumsalvo":
          makeMagnumSalvoPostDescription(tooltip, ship);
          break;
        case "ii_commandcenter":
          makeCommandCenterPostDescription(tooltip, ship);
          break;
        case "ii_shockbuster":
          makeShockBusterPostDescription(tooltip, ship);
          break;
        case "ii_celeritydrive":
          makeCelerityDrivePostDescription(tooltip, ship);
          break;
        case "ii_luxfinis":
          makeLuxFinisPostDescription(tooltip, ship);
          break;
        default:
          makeEmptySysModPostDescription(tooltip);
        }

      }

      if ((isForModSpec) || (ship == null) || (ship.getSystem() == null)) {
        heading = tooltip.addSectionHeading("其他强化", 
          Global.getSettings().getColor("tooltipTitleAndLightHighlightColor"), Global.getSettings().getColor("buttonBgDark"), Alignment.TMID, 10.0F);
        makeEmptyMiscModPostDescription(tooltip);
      } else {
        String shipId = II_Util.getNonDHullId(ship.getHullSpec());
        switch (shipId)
        {
        case "ii_carrum":
        case "ii_barrus":
          heading = tooltip.addSectionHeading("其他强化", 
            Global.getSettings().getColor("tooltipTitleAndLightHighlightColor"), Global.getSettings().getColor("buttonBgDark"), Alignment.TMID, 10.0F);
          makeCargoPostDescription(tooltip, ship);
          break;
        case "ii_adamas":
          heading = tooltip.addSectionHeading("其他强化", 
            Global.getSettings().getColor("tooltipTitleAndLightHighlightColor"), Global.getSettings().getColor("buttonBgDark"), Alignment.TMID, 10.0F);
          makeLightspearPostDescription(tooltip, ship);
          break;
        case "ii_olympus":
          heading = tooltip.addSectionHeading("其他强化", 
            Global.getSettings().getColor("tooltipTitleAndLightHighlightColor"), Global.getSettings().getColor("buttonBgDark"), Alignment.TMID, 10.0F);
          makeTitanPostDescription(tooltip, ship);
        }
      }
    }
  }

  public String getUnapplicableReason(ShipAPI ship)
  {
    if ((ship != null) && (ship.getVariant().getHullMods().contains("ii_armor_package")) && (!getHullModId().contentEquals("ii_armor_package"))) {
      return "不兼容于 帝国装甲套件";
    }
    if ((ship != null) && (ship.getVariant().getHullMods().contains("ii_targeting_package")) && (!getHullModId().contentEquals("ii_targeting_package"))) {
      return "不兼容于 帝国火控套件";
    }
    if ((ship != null) && (ship.getVariant().getHullMods().contains("ii_elite_package")) && (!getHullModId().contentEquals("ii_elite_package"))) {
      return "不兼容于 帝国精英套件";
    }
    if ((ship != null) && (((ship.getVariant().getHullMods().contains("ii_no_package")) || (ship.getVariant().getHullMods().contains("swp_no_package")))) && 
      (!getHullModId().contentEquals("ii_no_package")) && (!getHullModId().contentEquals("swp_no_package"))) {
      return "无法安装 帝国强化套件";
    }
    if ((ship != null) //&& (!ship.getHullSpec().getHullId().startsWith("ii_"))) {
      return "必须安装在 星际帝国 的舰船上";
    }
    return null;
  }

  public boolean isApplicableToShip(ShipAPI ship)
  {
    if (ship == null) {
      return false;
    }
    if ((ship.getVariant().getHullMods().contains("ii_armor_package")) && (!getHullModId().contentEquals("ii_armor_package"))) {
      return false;
    }
    if ((ship.getVariant().getHullMods().contains("ii_targeting_package")) && (!getHullModId().contentEquals("ii_targeting_package"))) {
      return false;
    }
    if ((ship.getVariant().getHullMods().contains("ii_elite_package")) && (!getHullModId().contentEquals("ii_elite_package"))) {
      return false;
    }
    if ((((ship.getVariant().getHullMods().contains("ii_no_package")) || (ship.getVariant().getHullMods().contains("swp_no_package")))) && 
      (!getHullModId().contentEquals("ii_no_package")) && (!getHullModId().contentEquals("swp_no_package"))) {
      return false;
    }
    return ship.getHullSpec().getHullId().startsWith("ii_");
  }
}
sbndjgg(前端大神) - 2020-07-03 0 人
II_BasePackage
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Sf1 {
    public static void main(String[] args) {
        final int ts = 2;

        List<List<Fa>> fas = new ArrayList<List<Fa>>();
        for (int i = 0; i < ts; i++) {
            List<List<Fa>> cp = copy(fas);
            init(fas, Fa.FA1);
            init(cp, Fa.FA2);
            fas.addAll(cp);
        }
        fas.sort((a, b) -> (int) (100 * (fa(a) - fa(b))));
        System.out.println("最低:"+fa(fas.get(0)) + "-" + fas.get(0));
        System.out.println("最高:"+fa(fas.get(fas.size() - 1))+"-"+fas.get(fas.size() - 1));
    }

    static void init(List<List<Fa>> fas, Fa fa) {
        if (fas.isEmpty()) {
            List<Fa> fal = new ArrayList<Fa>();
            fal.add(fa);
            fas.add(fal);
        } else {
            fas.forEach(fai -> {
                fai.add(fa);
            });
        }
    }

    static List<List<Fa>> copy(List<List<Fa>> fas) {
        return fas.stream().map(ArrayList::new).collect(Collectors.toList());
    }

    static double fa(List<Fa> faList) {
        double dtf = 0;
        double gjf = 0;
        final double[] dtp1 = {100, .8};
        final double[] dtp2 = {150, .5};
        final double[] dtp3 = {400, 1};
        for (Fa fa : faList) {
            if (dtf <= dtp1[0] || dtf > dtp3[0]) {
                dtf += fa.ditie;
            } else if (dtf <= dtp2[0]) {
                dtf += fa.ditie * dtp1[1];
            } else {
                dtf += fa.ditie * dtp2[1];
            }
            gjf += fa.gongjiao;
        }
        return dtf + gjf;
    }

    enum Fa {
        /**
         * 方案1 地铁4,公交2 方案2 地铁6,公交1
         */
        FA1(4, 2), FA2(6, 1);
        private double ditie;
        private double gongjiao;

        @Override
        public String toString() {
            return "{d:" + ditie + ",g:" + gongjiao + "}";
        }

        Fa(int ditie, int gongjiao) {
            this.ditie = ditie;
            this.gongjiao = gongjiao;
        }
    }

}
feir(Non Is Every) - 2020-07-01 0 人
计算单位天数内北京地铁坐车方案最贵和最便宜方案
class Main {
	package homework1

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {
       
         public static void main(String[] args) throws IOException {
         Socket socket = new Socket(host:"127.0.0.1",port:7777);
         OutputSream os = socket.getOutputSream();
         InputStream is = socket.getInputSream();
         Scanner sc = new Scanner(System.in);
         String msg;
         do {
                   System.out.print("客户端:");
                   msg = sc.next();
                   os.write(msg.getBytes());
                   byte[]  byte = new byte[1024];
                   int len = is.read(bytes);
                   System.out.println("服务器端:" + new String(bytes, offest:0, len));
           }while((msg.equals("退出"))  != true);
          socket.close();
          }
}
}
steinonoobie(Toaru_Sucial()) - 2020-06-30 0 人
聊天小工具。
class Main {
	package homework1

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {
       
         public static void main(String[] args) throws IOException {
         Socket socket = new Socket(host:"127.0.0.1",port:7777);
         OutputSream os = socket.getOutputSream();
         InputStream is = socket.getInputSream();
         Scanner sc = new Scanner(System.in);
         String msg;
         do {
                   System.out.print("客户端:");
                   msg = sc.next();
                   os.write(msg.getBytes());
                   byte[]  byte = new byte[1024];
                   int len = is.read(bytes);
                   System.out.println("服务器端:" + new String(bytes, offest:0, len));
           }while((msg.equals("退出"))  != true);
          socket.close();
          }
}
}
13062332492(SCANF) - 2020-06-25 0 人
聊天小工具。
没有了
1/50 下一页