Boolean and IF Statements Lesson Hacks
My attempt at this unit hw
public int getChargeStartTime(int chargeTime)
{
int cheapestStartHour = 0;
for(int startHour = 1; startHour < rateTable.length; startHour++)
if(getChargingCost(startHour, chargeTime) <
getChargingCost(cheapestStartHour, chargeTime))
cheapestStartHour = startHour;
return cheapestStartHour;
}
import java.util.*;
public class Digits {
private ArrayList<Integer> digitList;
public Digits(int num) {
digitList = new ArrayList<Integer>();
if (num==0){
digitList.add(new Integer(0));
}
while (num > 0) {
digitList.add(0, new Integer(num % 10));
num /= 10;
}
}
public boolean isStrictlyIncreasing() {
boolean increase = true;
for (int i = 0; i < digitList.size() - 1; i++) {
if (digitList.get(i).intValue() >= digitList.get(i + 1).intValue()) {
increase = false;
return increase;
}
}
return increase;
}
}
System.out.println(new Digits(1356).isStrictlyIncreasing());
System.out.println(new Digits(1536).isStrictlyIncreasing());
public boolean isBalanced(ArrayList<String> delimiters) {
int openDels = 0;
int closeDels = 0;
for (String del : delimiters) {
if (del.equals(openDel)) {
openDels++;
} else {
closeDels++;
}
if (closeDels > openDels) {
return false;
}
}
return openDels == closeDels;
}