hpilo

Chapter5_Arrays_Ex4

Dec 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*
  3. =====================================================
  4. chapter 5: Arrays
  5.  
  6. Ex4: sum of each pair values
  7. =====================================================
  8. */
  9.  
  10. public class MyProgram {
  11. public static void main(String[] args) {
  12. final int SIZE=5;
  13. int arr[]=new int[SIZE];
  14. int num;
  15.  
  16. boolean flag=true;
  17. Scanner s=new Scanner(System.in);
  18.  
  19. System.out.println("Enter "+SIZE+" values: ");
  20. for(int i=0;i<arr.length;i++){
  21. arr[i]=s.nextInt();
  22. }
  23. System.out.println("Enter a number: ");
  24. num=s.nextInt();
  25.  
  26. for(int i=1;i<arr.length ;i++){
  27. if(arr[i-1]+arr[i]!=num)
  28. {
  29. System.out.println("False!");
  30. flag=false;
  31. break;
  32. }
  33. }
  34. if(flag)
  35. System.out.println("True!");
  36.  
  37.  
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment