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
__author__ = 'Pac' | |
import collections | |
Card = collections.namedtuple('Card', ['rank', 'suit']) | |
class FrenchDeck: | |
ranks = [str(n) for n in range(2, 11)] + list('JQKA') | |
suits = 'spades diamonds clubs hearts'.split() |
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
#include <stdio.h> | |
typedef struct node | |
{ | |
int data; | |
struct node *next; | |
}; | |
struct node* reverse(struct node* head) |
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
class Object2 { | |
int y, x, z; | |
Object2 () { // constructor | |
y = 5; x = 2; z = 1; | |
} | |
public int doAnother() { | |
y += 1; | |
return y; | |
} |
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
class MyRobo { | |
int x = 5; | |
static int y = 6; | |
} | |
class Untitled { | |
public static void main(String[] args) { | |
MyRobo robo1 = new MyRobo(); | |
MyRobo robo2 = new MyRobo(); | |
robo1.x += 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
import java.util.Scanner; | |
class TriangleArea { | |
public static void main(String[] args) { | |
Scanner kb = new Scanner(System.in); | |
System.out.println("This program will help you calculate the area of a triangle."); | |
System.out.print("What's the height of the triangle? "); |
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
import java.util.*; | |
class Untitled { | |
public static void main(String[] args) { | |
String string = "5,6,7,8"; | |
String[] strings = string.split(","); // this array has 4 numbers | |
// "for loop" first example | |
for(String str : strings) // for loop difference |
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
class Untitled { | |
public static void main(String[] args) { | |
// Static method | |
add2(1, 4); | |
// Non-static method | |
Untitled object = new Untitled(); | |
object.add1(1, 4); | |
} | |
public double add1(int x, int y) |
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
class Untitled { | |
public static void main(String[] args) { | |
int [] array = {1,5,2,-1}; | |
// sort | |
for(int k = 0; k<array.length; k++){ | |
for(int i = k; i<array.length; i++){ | |
if(array[i]<array[k]){ | |
int temp = array[k]; |
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
class Untitled { | |
public static void main(String[] args) { | |
int [][] k ={ | |
{1,2}, // first element of k | |
{3,4,5}, // second element of k | |
{8,10,12,14} // third element of k | |
}; | |
System.out.println(k.length); | |
System.out.println(k[0].length); | |
System.out.println(k[1].length); |
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 Untitled { | |
// int is called "return value" | |
// someFunction is called "method" | |
// return is the Java keyword which returns result | |
int someFunction(int n) { | |
if(n==0) | |
return 0; | |
else | |
return someFunction(n-1) + n; | |
} |
OlderNewer