Created
March 22, 2015 21:32
-
-
Save ad-m/37dde082878f0398d18a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SimplyCheck implements TenArray.Checkable{ | |
| public boolean check(int i, int j) { | |
| if(i == 0){ return (j == 1 ? true : false); }; | |
| if(j == 0){ return (i == 1 ? true : false); }; | |
| while (i != j) { | |
| if (i > j) { | |
| i -= j; | |
| } else { | |
| j -= i; | |
| } | |
| } | |
| return (i == 1 ? true : false); | |
| } | |
| } |
This file contains hidden or 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
| /* Zadanie 3 | |
| Napisz program wypełniający tablicę 10x10 wartościami 0 lub 1, który | |
| będzie nadawał elementowi [i][j] wartośd 1 jeżeli największy | |
| wspólny dzielnik i oraz j wynosi 1, a 0 w przeciwnym wypadku. | |
| Program powinien wypisad wartości tablicy w kształcie 10x10. */ | |
| public class TenArray{ | |
| public interface Checkable{ | |
| public boolean check(int i, int j); | |
| } | |
| boolean[][] array; | |
| int w; | |
| int h; | |
| private Checkable mCheck; | |
| public TenArray(int w, int h, Checkable mCheck) { | |
| this.w = w; | |
| this.h = h; | |
| this.mCheck = mCheck; | |
| this.array = new boolean[w][h]; | |
| fillArray(); | |
| } | |
| private void fillArray() { | |
| for (int i = 0; i < w; i++) { | |
| for (int j = 0; j < h; j++) { | |
| this.array[i][j] = mCheck.check(i, j); | |
| } | |
| } | |
| } | |
| public void print() { | |
| for (int i = 0; i < w; i++) { | |
| for (int j = 0; j < h; j++) { | |
| System.out.print(this.array[i][j] ? "0 " : "1 "); | |
| } | |
| System.out.print("\n"); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| TenArray data = new TenArray(10, 10, new SimplyCheck()); | |
| data.print(); | |
| System.out.println("---"); | |
| TenArray data1 = new TenArray(5, 5, new Checkable() { | |
| @Override | |
| public boolean check(int i, int j) { | |
| return i % (j+1) == 1; | |
| } | |
| }); | |
| data1.print(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment