hpilo

Chapter5_Arrays_Ex5

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