Skip to content

Instantly share code, notes, and snippets.

@lb7n
Created August 18, 2014 01:21
Show Gist options
  • Save lb7n/26329a47ee62e56507eb to your computer and use it in GitHub Desktop.
Save lb7n/26329a47ee62e56507eb to your computer and use it in GitHub Desktop.
public class mainclass {
public static void main (String[] args)
{
String BREAK = "\n \n";
String ONE = "This is a string!! ~~ wooo";
String TWO = "This string has ";
String THREE = " Characters";
/*Strings are objects and have methods that can be accessed from them*/
int stringOneLength = ONE.length();
System.out.println( ONE + BREAK + TWO + stringOneLength + THREE);
/* data types are not objects, they just have a base value (int, double, float, char, boolean)*/
char firstChar = TWO.charAt(0);
char secondChar = 'o';
int[] dankArray2012 = new int [5];
/* arrays are declared by putting the type of array you want first and then the two brakets after,
* then the variable name, is equal to new number you want in brakets (the number in the brakets determines how large
* the array is
*/
dankArray2012 [0] = 1;
dankArray2012 [1] = 2;
dankArray2012 [2] = 3;
dankArray2012 [3] = 4;
dankArray2012 [4] = 5;
int dankArrayLength = dankArray2012.length;
/* arrays start with zero and the last number would be minus one because counting starts at zero*/
System.out.println(dankArray2012[0] + BREAK + dankArray2012[1] + BREAK + dankArray2012[2] +
BREAK + dankArray2012[3] +BREAK + dankArray2012[4] + BREAK);
int total = dankArray2012[0]+dankArray2012[1]+dankArray2012[2]+dankArray2012[3]+dankArray2012[4];
int average = total/dankArrayLength;
System.out.println("The total of all of these numbers is equal to: "+ total);
System.out.println("The average of all of these numbers is equal to: " + average);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment