Advertisement
hpilo

Chapter5_Arrays_Ex3

Dec 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*
  3. =====================================================
  4. chapter 5: Arrays
  5.  
  6. Ex3: init array -each value the sum of 2 prev
  7. =====================================================
  8. */
  9.  
  10. public class MyProgram {
  11. public static void main(String[] args) {
  12. final int SIZE=10;
  13. int arr[]=new int[SIZE];
  14.  
  15. Scanner s=new Scanner(System.in);
  16.  
  17. System.out.println("Enter 2 values: ");
  18. arr[0]=s.nextInt();
  19. arr[1]=s.nextInt();
  20.  
  21. for(int i=2; i<arr.length;i++){
  22. arr[i]=arr[i-2]+arr[i-1];
  23. }
  24.  
  25. for(int n: arr){
  26. System.out.print(n+" ");
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement