Created
February 24, 2014 15:14
-
-
Save DavidCulpepper/9190126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Errors | |
{ | |
public static void Main(String[] args) // Main to lowercase (main) | |
{ | |
String s = "Hello World!"; | |
int i = 0; | |
{ | |
if (s.equals(Hello World!)) // Hello World! -> "Hello World!" | |
System.out.println(s) // Semicolon at end | |
} | |
while i < 100 // Surround condition with () | |
{ | |
if (i % 5 == 0) | |
System.out.println(i); | |
i++; | |
} | |
if (calcSum(5, 5) = 10) // single = to == | |
i = 1000; | |
} | |
private static int calcSum(int a, int b) | |
{ | |
return (a + b); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int[][] matrix = new int[10][10]; | |
for (int i = 0; i < matrix.length; i++) { | |
for (int j = 0; j < matrix[i].length; j++) { | |
if (i == j) { | |
matrix[i][j] = 0; | |
} else if (i > j) { | |
matrix[i][j] = -1; | |
} else { | |
matrix[i][j] = 1; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList<Integer> values = new ArrayList<Integer>(); // The first ArrayList could be just List | |
values.add(10); | |
values.add(100); | |
values.add(342); | |
for (int i = 642331; i > 0; i -= 21) { | |
values.add(i); | |
} | |
boolean findWhile(ArrayList<Integer> values, int search) { | |
int i = 0; | |
while (i < values.size()) { | |
if (values.get(i) == search) return true; | |
i++; | |
} | |
return false; | |
} | |
boolean findFor(ArrayList<Integer> values, int search) { | |
int i = 0; | |
for (int i = 0; i < values.size(); i++) { | |
if (values.get(i) == search) return true; | |
} | |
return false; | |
} | |
boolean findForEach(ArrayList<Integer> values, int search) { | |
for (Integer i : values) { | |
if (i == search) return true; | |
} | |
return false; | |
} | |
int largest(ArrayList<Integer> values) { | |
int largestIndex = 0; | |
for (int i = 1; i < values.size(); ++i) { | |
if (values.get(i) > values.get(largestIndex)) { | |
largestIndex = i; | |
} | |
} | |
return largestIndex; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int[] fib = new int[35]; | |
fib[0] = 0; | |
fib[1] = 1; | |
for (int i = 2; i < fib.length; i++) { | |
fib[i] = fib[i - 1] + fib[i - 2]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Fraction { | |
private int numerator; | |
private int denominator; | |
public Fraction() { | |
this(0, 1); | |
} | |
public Fraction(int numerator, int denominator) { | |
this.numerator = numerator; | |
if (denominator == 0) throw new IllegalArgumentException(); | |
this.denominator = denominator; | |
} | |
public int getNumerator() { | |
return numerator; | |
} | |
public void setNumerator(int numerator) { | |
this.numerator = numerator; | |
} | |
public int getDenominator() { | |
return denominator; | |
} | |
public void setDenominator(int denominator) { | |
if (denominator == 0) throw new IllegalArgumentException(); | |
this.denominator = denominator; | |
} | |
public double getReal() { | |
return (double) numerator / denominator; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment