online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; class Ship { private boolean shipwreck; private int size; private static ShipSizeLimit limit; static int i; static ArrayList<Integer> limits = new ArrayList<>(); static HashMap<Integer, List<Ship>> ships = new HashMap<>(); private Ship() { } public static void setLimit(ShipSizeLimit limit) { Ship.limit = limit; limits.clear(); for(i=0; i<limit.getNumberOfSizes(); i++) { limits.add(limit.getLimit(i)); } } private static List<Ship> getList(int index) { if(ships.containsKey(index)) return ships.get(index); else { ArrayList<Ship> counter = new ArrayList<>(); ships.put(index, counter); } return ships.get(index); } public static Ship getShip(int size) { if(limits.isEmpty()) return null; else if(size == 0) return null; else if(size > limits.size() || size < limits.get(0)) return null; else if(ships.containsKey(size)) { for(i=0; i<limits.get(size-1); i++) { if(ships.get(size).get(i).isShipwreck()) { limits.set(size-1, limits.get(size-1) + 1); } } } else if(limits.get(size-1) > 0) { if(ships.containsKey(size) && (ships.get(size).size() < limits.get(size-1).intValue())) { List<Ship> counter = getList(size); Ship ship = new Ship(); counter.add(ship); ships.put(size, counter); limits.set(size-1, limits.get(size-1) - 1); //return ships.get(size).iterator().next(); } else if((!ships.containsKey(size)) && (limits.get(size-1).intValue() > 0)) { List<Ship> counter = getList(size); Ship ship = new Ship(); counter.add(ship); counter.set(size, ship); ships.put(size, counter); limits.set(size-1, limits.get(size-1) - 1); //return ships.get(size).iterator().next(); } } return ships.get(size).iterator().next(); } public void shipwreck() { shipwreck = true; } public boolean isShipwreck() { return shipwreck; } } final class ShipSizeLimit { private final int[] shipSizes; public ShipSizeLimit(int[] shipSizes) { this.shipSizes = new int[shipSizes.length]; System.arraycopy(shipSizes, 0, this.shipSizes, 0, shipSizes.length); } final public int getNumberOfSizes() { return shipSizes.length; } final public int getLimit(int size) { if (size == 0) return 0; return shipSizes[size - 1]; } } class Main { public static void main(String [ ] args) { int[] tab = new int[1]; tab[0] =2; ShipSizeLimit lim = new ShipSizeLimit(tab); Ship.setLimit(lim); Ship.getShip(1); //if(Ship.getShip(1) != null) //System.out.println("not null"); } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue