Skip to content

Instantly share code, notes, and snippets.

View jweinst1's full-sized avatar
🎯
Focusing

Josh Weinstein jweinst1

🎯
Focusing
View GitHub Profile
@jweinst1
jweinst1 / maxfunctionforarray.Java
Created September 1, 2015 07:14
max function implementation in java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(maxval(lst));
}
static int[] lst = {1, 2, 3};
static int maxval(int[] x) {
int size = x.length;
int counter = 0;
@jweinst1
jweinst1 / ReverseArray.java
Created September 1, 2015 07:29
Returns a Reversed Version of an Array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(reversed(lst)));
}
static int[] lst = {1, 2, 3, 4, 5};
static int[] reversed(int[] x){
int size = x.length;
int[] xcopy = new int[size];
@jweinst1
jweinst1 / SwapArrayItem.java
Created September 1, 2015 17:37
Swaps two items in an array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(swapitem(lst, 3, 1)));
}
static int[] lst = {2, 3, 1, 5, 6, 7};
static int[] swapitem(int[] x, int y, int z) {
int temp = x[y];
x[y] = x[z];
@jweinst1
jweinst1 / Checkifsorted.java
Created September 1, 2015 18:12
Checks if an Int array is sorted in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(issorted(lst));
}
static int[] lst = {1, 0, 2, 3};
static boolean issorted(int[] x) {
int size = x.length;
for(int i=0; i<size-1; i++) {
@jweinst1
jweinst1 / SortThreeItemArray.java
Created September 1, 2015 18:29
sorts an int array of length in java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(sortthree(lst)));
}
static int[] lst = {8, 5000, 6};
static int[] sortthree(int[] x) {
while (issorted(x) == false) {
if (x[0] > x[1]) {
@jweinst1
jweinst1 / SliceArray.java
Created September 1, 2015 18:47
returns a slice of an array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(slicearray(lst, 3, 6)));
}
static int[] lst = {1, 2, 3, 4, 5, 6, 7, 8, 9};
static int[] slicearray(int[] x, int start, int end) {
int size = (end - start) + 1;
int[] slice = new int[size];
@jweinst1
jweinst1 / WordcountString.java
Created September 2, 2015 21:57
word count for a string based on number of spaces in java.
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(wordcount(statement));
}
static String statement = "The apples are red.";
static int wordcount(String x) {
char[] charlist = x.toCharArray();
int count = 0;
@jweinst1
jweinst1 / SentenceObjects.py
Created September 4, 2015 08:33
SentenceObjects.py
from strmodfunctions import *
#linked list that links togeter a sentence.
class Word (object):
def __init__(self, first=None, rest=None):
self.first = first
self.rest = rest
def get_data(self):
return self.first
@jweinst1
jweinst1 / transfertext.html
Created September 6, 2015 18:54
basic html template to take input text and transfer the text onto another form.
<!DOCTYPE html>
<html>
<body>
<form>
Input Text:<br>
<input type="text" id="input" name="firstname">
<br>
Output Text:<br>
<input type="text" id="output" name="lastname">
@jweinst1
jweinst1 / textfunctionsimulator.html
Created September 6, 2015 20:57
basic container and input to control text editing or textfunctions in javascript
<!DOCTYPE html>
<html>
<body>
<div class="boxed">
<form>
Input Text:<br>
<input type="text" id="input" name="firstname" size="70">
</form>
<br>Output Text:<br>