Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int unsortedAt(int[] a) {
- for (int i = 1; i < a.length; i++)
- if (a[i] < a[i - 1])
- return i - 1;
- return -1;
- }
- public static void swap(int[] a, int i) {
- int temp = a[i + 1];
- a[i + 1] = a[i];
- a[i] = temp;
- }
- public static void sort(int[] a) {
- int i = unsortedAt(a);
- while (i != -1) {
- swap(a, i);
- i = unsortedAt(a);
- }
- }
- public static int spiderman(int n) {
- if (n == 0 || n == 1)
- return 1;
- return spiderman(n - 1) + spiderman(n - 2);
- }
- public static void printBinary(int n) {
- String s = new String();
- s = getBinary(n, s);
- for (int i = s.length() - 1; i >= 0; i--) {
- System.out.print(s.charAt(i));
- }
- }
- public static String getBinary(int n, String s) {
- if (n != 0) {
- s += n % 2;
- return getBinary(n / 2, s);
- } else
- return s;
- }
- public static boolean isPalindrome(String s) {
- for (int i = 0; i < s.length() / 2; i++)
- if (s.charAt(i) != s.charAt(s.length() - 1 - i))
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement