Advertisement
asrulsibaoel

java

Jan 16th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. package javaapplication2;
  2.  
  3. /**
  4. *
  5. * @author asrulsibaoel
  6. */
  7. public class JavaApplication2 {
  8.  
  9. private int[] C = {101001};
  10.  
  11. /**
  12. * @param args the command line arguments
  13. */
  14. public static void main(String[] args) {
  15. JavaApplication2 coba = new JavaApplication2();
  16. System.out.println(coba.f2(6));
  17. }
  18.  
  19. private int f2(int n) {
  20. int p = 1;
  21. int h = 0;
  22. for (int i = 0; i < n; i++) {
  23. h = h + (C[i] - 48) * p;
  24. p = p * 3;
  25. }
  26.  
  27. return h;
  28. }
  29.  
  30. }
  31.  
  32.  
  33.  
  34. //return output -17219
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement