Richard_Sekol

projrct 6.2

Oct 24th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. package chapter5;
  2.  
  3. public class Project62 {
  4.  
  5. public static void main(String[] args) {
  6. int fold1 = 1;
  7. int fold2 = 1;
  8. int foldNew = fold1 + fold2;
  9.  
  10.  
  11. Scanner s = new Scanner(System.in);
  12. System.out.println("enter an integer n");
  13. int nthPosition = s.nextInt();
  14.  
  15. if(nthPosition == 1)
  16. {
  17. foldNew = 1;
  18. }
  19. else if(nthPosition == 2)
  20. {foldNew = 1;}
  21. else if(nthPosition == 3)
  22. {foldNew = 2;}
  23. else if(nthPosition > 3)
  24. {for(int i = 1; i <= (nthPosition - 3); i++)
  25. {
  26. fold2 = fold1;
  27. fold1 = foldNew;
  28. foldNew = fold2 + fold1;
  29. }
  30.  
  31. }
  32. System.out.println(foldNew);
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment