Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import java.util.Arrays;
- /*
- * write a method in java that returns the sum of tens of a given array of numbers
- */
- public class Practice1 {
- public static void main(String[] args) {
- System.out.println((reverseArr(new int[]{-9, 10, 120, 1089,})));
- }
- public static int reverseArr(int[] num){
- int[] nnum = new int [] {};
- int total = 0;
- for(int i = 0, j = 0; i < num.length; i++, j++)
- {
- if(num[i] < 10){
- nnum[j] = 0;
- }
- if(num[i] >= 10) {
- nnum[j] = (num[i] / 10) % 10;
- }
- total += nnum[j];
- }
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement