Erinevus lehekülje "ITI0011:Kordamine eksamiks" redaktsioonide vahel
Mine navigeerimisribale
Mine otsikasti
| (ei näidata sama kasutaja 5 vahepealset redaktsiooni) | |||
| 81. rida: | 81. rida: | ||
if (i % (i % 3 + 1) == 1) continue; | if (i % (i % 3 + 1) == 1) continue; | ||
sum += i; | sum += i; | ||
| + | } | ||
| + | |||
| + | sum = 0; | ||
| + | for (int i = 0, j = 5; i < 5 || i < j; i++) { | ||
| + | //System.out.println("i:" + i + " j:" + j); | ||
| + | sum += i++; | ||
| + | sum += ++j; | ||
| + | } | ||
| + | System.out.println(sum); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | public class Hello { | ||
| + | public static int y = 1, x = 100; | ||
| + | |||
| + | public static void main(String[] args) { | ||
| + | int x = 0; | ||
| + | int z = x + 0; | ||
| + | |||
| + | System.out.println("main x,y,z: " + x + " " + y + " " + z); | ||
| + | z = world(hello(x), y); | ||
| + | System.out.println("main x,y,z: " + x + " " + y + " " + z); | ||
| + | } | ||
| + | |||
| + | public static void hello(int x, int z) { | ||
| + | x = z + 100; | ||
| + | System.out.println("hello(world(x, z))"); | ||
| + | } | ||
| + | |||
| + | public static int hello(int x) { | ||
| + | int y = 0; | ||
| + | ++x; | ||
| + | while (x < 100) { | ||
| + | if (y > 2) | ||
| + | continue; | ||
| + | break; | ||
| + | } | ||
| + | System.out.println("hello x,y: " + (x - 2) + " " + y); | ||
| + | return x; | ||
| + | } | ||
| + | |||
| + | public static int world(int x, int z) { | ||
| + | int y = 0; | ||
| + | y++; | ||
| + | while (y++ <= 3) | ||
| + | z *= y; | ||
| + | System.out.println("world x,z++,z: " + x + " " + z + " " + z); | ||
| + | return z; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | public class MisTeeb { | ||
| + | public static int a = 1; | ||
| + | public static int b = 10; | ||
| + | |||
| + | public static void main(String[] args) { | ||
| + | int c = foo(bar(a, a)) + (foo()); | ||
| + | System.out.println("a:" + a); | ||
| + | System.out.println("b:" + b); | ||
| + | System.out.println("c:" + c); | ||
| + | |||
| + | int u = 12; | ||
| + | for (int i = --b; i++ > 0; i -= 3) { | ||
| + | u += i; | ||
| + | } | ||
| + | System.out.println("u:" + u); | ||
| + | |||
| + | String s = "oterave"; | ||
| + | for (u = 0; u < 3; u++) { | ||
| + | System.out.print(s.substring(u, 2 * u)); | ||
| + | } | ||
| + | System.out.println(s.charAt(u * 2)); | ||
| + | } | ||
| + | |||
| + | public static int foo() { | ||
| + | return foo(a); | ||
| + | } | ||
| + | |||
| + | public static int foo(int b) { | ||
| + | System.out.println("foo a:" + a++ + " b:" + b); | ||
| + | return a; | ||
| + | } | ||
| + | |||
| + | public static int bar(int a, int c) { | ||
| + | System.out.println("bar c:" + c + " a:" + a); | ||
| + | a++; | ||
| + | while (a++ <= c) c++; | ||
| + | return b + c; | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | |||
| + | === 6.6.16 === | ||
| + | |||
| + | <pre> | ||
| + | public class Cmon { | ||
| + | public static int b = -3; | ||
| + | public static int a = 0; | ||
| + | public static void main(String[] args) { | ||
| + | int foo = foo(b + foo(bar() + b) + b); | ||
| + | |||
| + | System.out.println("foo:" + foo); | ||
| + | System.out.println("a:" + a++); | ||
| + | System.out.println("b:" + b); | ||
| + | int sum = 0; | ||
| + | for (int i = 0; i + 2 < 9; a++) { | ||
| + | sum += a + i++; | ||
| + | } | ||
| + | System.out.println("sum:" + sum); | ||
| + | |||
| + | String s = "SIKAP"; | ||
| + | for (int u = 8; u < 12; u = (u + 8) % 14) { | ||
| + | System.out.print(s.substring(u / 4, u / 2)); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public static int foo(int a) { | ||
| + | System.out.println("foo a: " + a + " b:" + b++); | ||
| + | int b = a++; | ||
| + | a = b++; | ||
| + | b = a++; | ||
| + | return a-- + --b; | ||
| + | } | ||
| + | |||
| + | public static int bar() { | ||
| + | System.out.println("bar b:" + b++); | ||
| + | int a = b - 2; | ||
| + | while (a < b) { | ||
| + | a++; | ||
| + | } | ||
| + | return b + a; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | int i = 3, j = 3, z = 0; | ||
| + | while (i-- > 0) { | ||
| + | while (j-- > 0) { | ||
| + | if (i + j == i) { | ||
| + | z += i; | ||
} | } | ||
} | } | ||
| + | if (i + j == j) { | ||
| + | z += j; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | z? | ||
| + | |||
| + | </pre> | ||
| + | <pre> | ||
| + | double a = 4 / 0.01; | ||
| + | double b = 8 / 3; | ||
| + | double c = a / b; | ||
| + | |||
| + | a + 3 * b + c? | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | int sum = -1; | ||
| + | for (int i = 1; i <= 5; i++) { | ||
| + | if (i % 7 == i + i) { | ||
| + | break; | ||
| + | } else if (i % 3 == 0) { | ||
| + | sum += 3; | ||
| + | } else if (i % 5 == 0 || i % 3 == 0) { | ||
| + | sum += 2; | ||
| + | } | ||
| + | sum = sum + 1; | ||
} | } | ||
| + | sum? | ||
</pre> | </pre> | ||
| + | <!-- | ||
| + | == GUI == | ||
| + | |||
| + | Kirjuta programmi osa, mis hiire vajutamise korral märgistab ära hiire asukohale kõige lähema ristküliku. Hiire kaugust ristkülikust tuleb mõõta ristküliku keskpunkti suhtes. | ||
| + | |||
| + | Write a part of a program which in case of mouse click highlights the closest rectangle to the mouse. The distance from the mouse position is calculated using the centre of the rectangle. | ||
| + | |||
| + | Helpful stuff: | ||
| + | <pre> | ||
| + | Rectangle object – all the shapes in the given pane is guaranteed to be of that shape. Subclass of Node. | ||
| + | r.getX(), r.getY() – x (left side) and y (upper side) for the rectangle r | ||
| + | r.getWidth(), r.getHeight() – width and height of the rectangle r. | ||
| + | ObservableList<Node> pane.getChildren() – returns a list of all the children (in our case, all the rectangles). | ||
| + | For highlighting: r.setFill(Color.RED) can be used, where r is the object to be highlighted. | ||
| + | </pre> | ||
| + | <source lang="java"> | ||
| + | public class Rect extends Application { | ||
| + | |||
| + | |||
| + | public void start(Stage stage) throws Exception { | ||
| + | Pane pane = new Pane(); | ||
| + | |||
| + | pane.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { | ||
| + | public void handle(MouseEvent event) { | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | } | ||
| + | }); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | </source> | ||
| + | --> | ||
Viimane redaktsioon: 6. juuni 2016, kell 04:13
Koodilugemine
public class First {
public static int a = 5;
public static int x = 10;
public static void main(String[] args) {
a = x;
x++;
int aa = a;
int y = x() + a(x) + x(x(aa));
System.out.println("main a:" + a + " x:" + x);
System.out.println("y:" + y);
int a = 2 * 4;
for (int i = a; i - 2 > 5 / 2; ) {
System.out.println(i);
a += i--;
}
System.out.println("a:" + a);
String s = "taskuuni";
String result = "";
for (a = 2; a < 4; a += 1) {
result = s.substring(a, 2 * a) + result;
}
System.out.println(result);
System.out.println(s.charAt(2) + result.substring(1));
}
public static int x() {
return a + 1;
}
public static int a(int a) {
//a = a++ + 1;
a = a + 2;
System.out.println(a);
for (int x = 0; a < 1; a++) ;
System.out.println("a a:" + a + " x:" + x);
return 0;
}
public static int x(int x) {
x++;
a--;
System.out.println("x a:" + a + " x:" + x);
return x;
}
}
public class ReadME{
public static void main(String[] args) {
int sum = 0;
for (int i = 0, j = 0; i++ < 5 ; i--) {
sum += i++;
}
System.out.println(sum);
sum = 0;
for (int i = 0, j = 0; i++ < 5 ; i--, j-=2) {
sum += i++ + j++;
}
System.out.println(sum);
int u = 13;
for (int i = u / 2; i++ < 12; i += 2) {
u += i;
}
System.out.println("u:" + u);
int sum = 0;
for (int i = 0; i < 5; i++) {
if (i % (i % 3 + 1) == 1) continue;
sum += i;
}
sum = 0;
for (int i = 0, j = 5; i < 5 || i < j; i++) {
//System.out.println("i:" + i + " j:" + j);
sum += i++;
sum += ++j;
}
System.out.println(sum);
}
}
}
public class Hello {
public static int y = 1, x = 100;
public static void main(String[] args) {
int x = 0;
int z = x + 0;
System.out.println("main x,y,z: " + x + " " + y + " " + z);
z = world(hello(x), y);
System.out.println("main x,y,z: " + x + " " + y + " " + z);
}
public static void hello(int x, int z) {
x = z + 100;
System.out.println("hello(world(x, z))");
}
public static int hello(int x) {
int y = 0;
++x;
while (x < 100) {
if (y > 2)
continue;
break;
}
System.out.println("hello x,y: " + (x - 2) + " " + y);
return x;
}
public static int world(int x, int z) {
int y = 0;
y++;
while (y++ <= 3)
z *= y;
System.out.println("world x,z++,z: " + x + " " + z + " " + z);
return z;
}
}
public class MisTeeb {
public static int a = 1;
public static int b = 10;
public static void main(String[] args) {
int c = foo(bar(a, a)) + (foo());
System.out.println("a:" + a);
System.out.println("b:" + b);
System.out.println("c:" + c);
int u = 12;
for (int i = --b; i++ > 0; i -= 3) {
u += i;
}
System.out.println("u:" + u);
String s = "oterave";
for (u = 0; u < 3; u++) {
System.out.print(s.substring(u, 2 * u));
}
System.out.println(s.charAt(u * 2));
}
public static int foo() {
return foo(a);
}
public static int foo(int b) {
System.out.println("foo a:" + a++ + " b:" + b);
return a;
}
public static int bar(int a, int c) {
System.out.println("bar c:" + c + " a:" + a);
a++;
while (a++ <= c) c++;
return b + c;
}
}
6.6.16
public class Cmon {
public static int b = -3;
public static int a = 0;
public static void main(String[] args) {
int foo = foo(b + foo(bar() + b) + b);
System.out.println("foo:" + foo);
System.out.println("a:" + a++);
System.out.println("b:" + b);
int sum = 0;
for (int i = 0; i + 2 < 9; a++) {
sum += a + i++;
}
System.out.println("sum:" + sum);
String s = "SIKAP";
for (int u = 8; u < 12; u = (u + 8) % 14) {
System.out.print(s.substring(u / 4, u / 2));
}
}
public static int foo(int a) {
System.out.println("foo a: " + a + " b:" + b++);
int b = a++;
a = b++;
b = a++;
return a-- + --b;
}
public static int bar() {
System.out.println("bar b:" + b++);
int a = b - 2;
while (a < b) {
a++;
}
return b + a;
}
}
int i = 3, j = 3, z = 0;
while (i-- > 0) {
while (j-- > 0) {
if (i + j == i) {
z += i;
}
}
if (i + j == j) {
z += j;
}
}
z?
double a = 4 / 0.01; double b = 8 / 3; double c = a / b; a + 3 * b + c?
int sum = -1;
for (int i = 1; i <= 5; i++) {
if (i % 7 == i + i) {
break;
} else if (i % 3 == 0) {
sum += 3;
} else if (i % 5 == 0 || i % 3 == 0) {
sum += 2;
}
sum = sum + 1;
}
sum?