# Average numbers that are greater than 70 from an Array.

• (2 Pages)
• 1
• 2

## 16 Replies - 629 Views - Last Post: 29 February 2016 - 12:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=389640&amp;s=f93650f17c995ff2b50ab0ac1c72a4ff&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

# Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:32 AM

I have this code so far:

```public class Array {
public static void main (String []args){

int[ ] abc = { 37, 14, 86, 99, 54 };
int total = 1;
for (int i = 2 ; i < abc.length; i++)
total = total + abc[i];

}
}

```

Would I need to use a if else statement to get numbers that are greater than 70 to be averaged out?

Thank you.
Is This A Good Question/Topic? 0

## Replies To: Average numbers that are greater than 70 from an Array.

### #2 ndc85430

• I think you'll find it's "Dr"

Reputation: 849
• Posts: 3,408
• Joined: 13-June 14

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:34 AM

Well, how do you think you can extract the values greater than 70 so you can just average those?

### #3 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12324
• Posts: 45,424
• Joined: 27-December 08

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:36 AM

Quote

Would I need to use a if else statement to get numbers that are greater than 70 to be averaged out?

This goes back to something I mentioned in your earlier thread. Programming isn't calculus. You don't learn by having someone tell you where each line of code goes. Programming is about logic. Think about the logic and (most importantly) try it! Otherwise, we won't be able to help you much.

### #4 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:36 AM

Grab the index of the elements that contain numbers that are greater than 70.

### #5 ndc85430

• I think you'll find it's "Dr"

Reputation: 849
• Posts: 3,408
• Joined: 13-June 14

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:37 AM

OK, that's one way to do it. So, like macosxnerd101 says, try it.

### #6 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:38 AM

Okay.

### #7 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:54 AM

Is it really this simple?

```public class Array {
public static void main (String []args){

double[ ] num = { 37, 14, 86, 99, 54 };
System.out.println("Numbers that are greater than 70 are, 86 and 99. Their average is: " + (num[2] +  + num[3]) / 2);
}
}

```

### #8 ndc85430

• I think you'll find it's "Dr"

Reputation: 849
• Posts: 3,408
• Joined: 13-June 14

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:56 AM

For this particular case, that works. What about if you wanted to do it for some arbitrary array? What would you do then?

This post has been edited by ndc85430: 29 February 2016 - 11:57 AM

### #9 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12324
• Posts: 45,424
• Joined: 27-December 08

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:56 AM

What if I gave you an arbitrary array where you (the developer) didn't know the values? Would your logic still work?

### #10 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:57 AM

Nope my code wouldn't work. I'd struggle making that program.

### #11 ndc85430

• I think you'll find it's "Dr"

Reputation: 849
• Posts: 3,408
• Joined: 13-June 14

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:57 AM

Developers are clearly tuned to thinking a certain way .

### #12 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:58 AM

I'm going to try it though.

### #13 ndc85430

• I think you'll find it's "Dr"

Reputation: 849
• Posts: 3,408
• Joined: 13-June 14

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 11:59 AM

Why are you struggling? You described the first step in your solution in post 4. What are you having difficulty with in making that work?

### #14 jshakil

Reputation: 0
• Posts: 202
• Joined: 04-February 16

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 12:03 PM

It would be on how to print numbers out that are greater than 70, without declaring the elements in which they're in.

What if I had 10 elements in the array, and had around six elements that were greater than 70. I would want to code something that would automatically grab elements that have numbers greater than 70 and then find the average.

### #15 ndc85430

• I think you'll find it's "Dr"

Reputation: 849
• Posts: 3,408
• Joined: 13-June 14

## Re: Average numbers that are greater than 70 from an Array.

Posted 29 February 2016 - 12:07 PM

Here's such an array of numbers then: [0, 14, 76, 91, 2, 88, -1, 18, 201]. Pretend you don't have a computer. Describe what you do to find the values greater than 70.