Skip to content

Instantly share code, notes, and snippets.

@mbakhoff
Created February 15, 2016 12:05
Show Gist options
  • Save mbakhoff/09ce24bc08ae687eb119 to your computer and use it in GitHub Desktop.
Save mbakhoff/09ce24bc08ae687eb119 to your computer and use it in GitHub Desktop.
oop 3. praks 2016-02-16
import java.util.Scanner;
class Scratch {
public static void main(String[] args) {
Node n1 = new Node(1);
n1.add(2);
n1.add(3);
n1.add(4);
Node.superValue = 1; // eiii
// class Rectangle
// pikkus, laius
// pindala, ümbermõõt
// scale(double) -> new Rectangle
int a = 42;
int b = a; // b 42
b = 0; // a 42
int[] x = { 42 };
int[] y = x; // y { 42 }
// y[0] = 0; // x { 0 }
// y = new int[]{ 0 }; // x { 42 }
int[] i1 = {10};
int[] i2 = {20};
swapFirst(i1, i2);
Math.min(1, 2);
java.util.Scanner scanner = new Scanner(System.in);
System.out.println("kirjuta midagi:");
String s = scanner.nextLine();
System.out.println(s);
System.out.println("kirjuta midagi veel:");
String s2 = scanner.nextLine();
System.out.println(s2);
}
static void swapFirst(int[] a, int[] b) {
int tmp = a[0];
a[0] = b[0];
b[0] = tmp;
}
}
// eraldi failis Node.java
public class Node {
private final int value;
static int superValue = 42; // non-final static muutujad on saatanast
Node next;
Node(int value) {
this.value = value;
superValue = 3; // eiiiii
}
void add(int nextValue) {
if (next == null) {
next = new Node(nextValue);
} else {
next.add(nextValue);
}
}
public String toString() {
return "node, value=" + value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment