Crenox

Puzzle4 Program

Feb 25th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. package com.samkough.headfirst;
  2.  
  3. public class Puzzle4
  4. {
  5. public static void main (String args[])
  6. {
  7. Puzzle4b[]obs = new Puzzle4b[6];
  8. int y = 1;
  9. int x = 0;
  10. int result = 0;
  11. while (x < 6)
  12. {
  13. obs[x] = new Puzzle4b();
  14. obs[x].ivar = y;
  15. y = y * 10;
  16. x = x + 1;
  17. }
  18. x = 6;
  19. while (x > 0)
  20. {
  21. x = x - 1;
  22. result = result + obs[x].doStuff(x);
  23. }
  24. System.out.println("result " + result);
  25. }
  26. }
  27.  
  28. ------------------------------------------------------------------------------------------------------------------
  29. package com.samkough.headfirst;
  30.  
  31. public class Puzzle4b
  32. {
  33. int ivar;
  34.  
  35. public int doStuff(int factor)
  36. {
  37. if (ivar > 100)
  38. {
  39. return ivar * factor;
  40. }
  41. else
  42. {
  43. return ivar *(5-factor);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment