SHARE
TWEET

Untitled

a guest Dec 2nd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2.  
  3. public class P11 implements IP11 {
  4.     private void printChar(char toPrint, int times) {
  5.         if (times > 0) {
  6.             System.out.print(toPrint);
  7.             printChar(toPrint, times - 1);
  8.         }
  9.     }
  10.  
  11.     private void printPattern(int stars, int stripes) {
  12.         if (stripes >= 0) {
  13.             printChar('*', stars);
  14.             printChar('-', stripes);
  15.             System.out.println();
  16.             printPattern(stars + 1, stripes - 1);
  17.         }
  18.     }
  19.  
  20.     @Override
  21.     public void printPattern(int n) {
  22.         printPattern(0, n);
  23.     }
  24.  
  25.     private int convertNum(int[] num, int idx, int lastIdx) {
  26.         if (idx == lastIdx) {
  27.             return num[idx];
  28.         } else {
  29.             return (int) (convertNum(num, idx + 1, lastIdx) + num[idx] * Math.pow(10, (lastIdx - idx)));
  30.         }
  31.     }
  32.  
  33.     @Override
  34.     public int convertNum(int[] num) {
  35.         return convertNum(num, 0, num.length - 1);
  36.     }
  37.  
  38.     private ArrayList<String> intersection(ArrayList<String> AL1, ArrayList<String> AL2, int remaining) {
  39.         if (remaining == 0) {
  40.             return new ArrayList<String>();
  41.         } else {
  42.             String item = AL1.remove(0);
  43.             ArrayList<String> res = intersection(AL1, AL2, remaining - 1);
  44.             if (AL2.contains(item)) {
  45.                 res.add(0, item);
  46.             }
  47.             return res;
  48.         }
  49.     }
  50.  
  51.     @Override
  52.     public ArrayList<String> intersection(ArrayList<String> AL1, ArrayList<String> AL2) {
  53.         return intersection( new ArrayList<String>(AL1), AL2, AL1.size());
  54.     }
  55.  
  56.     public static void main(String[] args) {
  57.         P11 inst = new P11();
  58.  
  59.         inst.printPattern(3);
  60.  
  61.         int[] num123 = {1, 2, 3};
  62.         System.out.println(inst.convertNum(num123));
  63.  
  64.         ArrayList<String> AL1 = new ArrayList<String>();
  65.         ArrayList<String> AL2 = new ArrayList<String>();
  66.         AL1.add("a");
  67.         AL1.add("b");
  68.         AL1.add("c");
  69.         AL2.add("b");
  70.         AL2.add("c");
  71.         AL2.add("d");
  72.         AL2.add("e");
  73.         ArrayList<String> intersect = inst.intersection(AL1, AL2);
  74.         System.out.println(AL1 + " intersect " + AL2 + " = " + intersect);
  75.     }
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top