Question: we have json data that is put into a custom object:

```
 "sentMoney": [
                {
                    "amount": 3840.83,
                    "currency": "MXN",
                    "isMajor": false
                },
                {
                    "amount": 200,
                    "currency": "USD",
                    "isMajor": true
                }
        ]

public final class SentMoney: NSCoding {
  public var currency: String?
  public var isMajor: Bool? = false
  public var amount: Double?
}

```

the custom object is then made reference to in a variable:

```
 public var sentMoney: [SentMoney]?

```

Now what we are trying to do is only get the FIRST amount (3840.83).

I tried doing it this way but there were errors:

```
 let amountsOnlyArray = self.postTransferSuccess?.sentMoney.map({ $0["amount"] })//Error -Cannot subscript a value of type '[SentMoney]' with an index of type 'String' 
 let firstAmountOnly = self.postTransferSuccess?.sentMoney![0]["amount"]//Error -Type 'BSentMoney' has no subscript members

```

Is there a better way to get that first amount?

Answer: 
You want to test if `i` is dividable by any number in the range of [2..i-1] and if it is, then it is not a prime number. Your `j`-loop starts at 1, that is the first error.

Knowing when a number is dividable by another is tested like this: `if (i % j == 0) {` (if the division remainder is zero) where in your code you test for equality with 1 instead.

Third thing is that you make your decision in the first iteration (when j is 1) and always print something in your inner loop. You need to take the logic out of the inner loop. Only if i is not dividable by **any** of the `j`s then it is prime.

Here is a modified version of your code:

```
static void primeNumbers(int n) {
    System.out.println("All the prime numbers up to "+n+" are -->\n");

    for (int i = 2; i < n; i++) {
        boolean isPrime = true;
        for (int j = 2; j < i; j++) {
            if(i % j != 0) {
                isPrime = false;
            }
        }
        if (isPrime) {
            System.out.print(i, " ");
        }
    }
}

```
Don't re-set `isPrime` to true in your second for loop, as soon as the number is not prime once, we know it is not prime forever. Just set it to true once every iteration of the outer loop, and do your final "Is prime" check outside.

```
static void isPrime(int n)
    {
         System.out.println("All the prime numbers up to "+n+" are -->\n");

        for(int i = 2; i <= n; i++)
        {
            boolean isPrime = true;
            for (int j = 2; j < i; j++)
            {

                if(i % j == 0)
                {
                    isPrime = false;
                    System.out.println(i + " is not prime because " + i + " is divisible by " + j );
                    break;
                }
            }
            if (isPrime){
              System.out.println(i + " is prime.");
            }
        }

    }

```

I've added a couple prints to this code so that you can see why each part of the logic is doing what it does -- compare it to your code so that you can understand why yours doesn't actually search for primes.