hpilo

Chapter5_Arrays_Ex9

Dec 15th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*
  3. =====================================================
  4. chapter 5: Arrays
  5.  
  6. Ex9: identical sum of digits
  7. =====================================================
  8. */
  9.  
  10. public class MyProgram {
  11. public static void main(String[] args) {
  12. final int SIZE=3;
  13. int arr1[]=new int[SIZE];
  14. int arr2[]=new int[SIZE];
  15. int a,b;
  16. int sumA=0;
  17. int sumB=0;
  18. boolean isMatch=true;
  19. Scanner s=new Scanner(System.in);
  20.  
  21. System.out.println("Array 1: enter valuse: ");
  22. for (int i=0;i< arr1.length;i++)
  23. arr1[i]=s.nextInt();
  24.  
  25. System.out.println("Array 2: enter valuse: ");
  26. for (int i=0;i< arr2.length;i++)
  27. arr2[i]=s.nextInt();
  28.  
  29. for(int i=0;i<arr1.length;i++){
  30.  
  31. a=arr1[i];
  32. b=arr2[i];
  33.  
  34. while(a>0){
  35. sumA+=a%10;
  36. a/=10;
  37. }
  38. while(b>0){
  39. sumB+=b%10;
  40. b/=10;
  41. }
  42. if(sumA!=sumB){
  43. System.out.println("not Match!");
  44. isMatch=false;
  45. break;
  46. }
  47.  
  48. }
  49.  
  50. if(isMatch)
  51. System.out.println("Match!");
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment