Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // import java.util.Arrays;
  2. /*
  3. * write a method in java that returns the sum of tens of a given array of numbers
  4. */
  5.  
  6. public class Practice1 {
  7. public static void main(String[] args) {
  8. System.out.println((reverseArr(new int[]{-9, 10, 120, 1089,})));
  9. }
  10.  
  11. public static int reverseArr(int[] num){
  12. int[] nnum = new int [] {};
  13. int total = 0;
  14. for(int i = 0; i <= num.length; i++)
  15. {
  16. if(num[i] < 10){
  17. nnum[i] = 0;
  18. }
  19. if(num[i] >= 10) {
  20. nnum[i] = (num[i] / 10) % 10;
  21. }
  22. total += nnum[i];
  23. }
  24.  
  25. return total;
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement