Skip to content

Instantly share code, notes, and snippets.

@chrisladd
Created September 29, 2014 19:44
Show Gist options
  • Save chrisladd/f4fe7ac6b5b443cc2b8c to your computer and use it in GitHub Desktop.
Save chrisladd/f4fe7ac6b5b443cc2b8c to your computer and use it in GitHub Desktop.
public class ForLoops {
public static void main(String[] args) {
for (int i = 99; i >= 0; i = i - 1) {
System.out.println(i + " bottles of root beer on the wall.");
}
// int numberOfRootBeerBottles = 99;
// System.out.println(numberOfRootBeerBottles + " bottles on the wall.");
//
// numberOfRootBeerBottles--;
// numberOfRootBeerBottles = numberOfRootBeerBottles - 1;
// numberOfRootBeerBottles -= 1;
//
// System.out.println(numberOfRootBeerBottles-- + " bottles on the wall.");
//
//
// System.out.println("98 bottles on the wall.");
// System.out.println("97 bottles on the wall.");
// System.out.println("96 bottles on the wall.");
// System.out.println("95 bottles on the wall.");
// System.out.println("99 bottles on the wall.");
// a for loop is used to execute the SAME STATEMENT multiple times.
// a for loop usually starts at zero
// but it can start anywhere
// it has three parts
// and it can go up by more than one
// or even down by more than one.
// compound interest means that you make a certain amount of money
// and then your reinvest what you earned, combined with the principal.
// for example:
/*
double interestRate = 0.025; // 2.5 % interest rate
double principal = 10000.0; // investment is 10 thousand dollars
double firstYearInterestEarned = principal * interestRate; // you make the principal times the interest rate on the first year.
System.out.println("First year: " + firstYearInterestEarned);
double secondYearInterestEarned = (principal + firstYearInterestEarned) * interestRate;
System.out.println("First year: " + secondYearInterestEarned);
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment