Assignment please Help :(

Our teacher was always on leave and so she doesn't teach us about java programming. She always leave a problem to us without even knowing how to deal with that kind of problem and what codes should we use for it.

Here's the problem I hope you can help me. :(

1. Write a program that would store the square of the first 7 even numbers (2, 4, 6, 8, 10, 12, 14) into array with 7 elements. Program must then display all the array elements together with its sum.

2. Barney has 10 children. Write a program that would enter the age of his 10 children into an array with 10 elements. The age of his youngest child will go into the 1st element and so on with the age of the oldest child going into the last element. Program must then display the following:

a. age of all his children form the oldest to the youngest.

b. The average age

c. Count of all teenagers (teenagers are from age 13 – 19, inclusive)

d. Count of all adults (adults are age 20 and above)

Re: Assignment please Help :(

That's not how this works. We are not a homework service. What have you done so far? Where are you stuck? Please read the link in my signature on asking smart questions, then post an SSCCE with a specific question.

You violated just about every unwritten rule about posting. Your post title is vague and will be ignored by most users. Complaining about your educator makes you seem lazy- many people here are self-taught, without the aid of a classroom, an educator, classmates, etc. And simply dumping your homework questions here pretty much guarantees that nobody is going to help you.

But like I said, post an SSCCE demonstrating what you tried and where you're stuck, ask a specific question, and we'll go from there.

Re: Assignment please Help :(

Uhm okay so I'm now only stuck with the number 2 problem I don't know the codes for how to output letter c and d

here's my code:

Code :

import java.util.Scanner;
import java.util.Arrays;
public class arrays{
public static void main(String args[]){
int sum=0;
int average;
int age = 10;
int []number = new int[age];
Scanner input = new Scanner(System.in);
for(int index=0; index<age; index++)
{
System.out.print("Enter Barney's children's age: ");
number[index] = input.nextInt();
}
Arrays.sort(number);
System.out.println("Ages of Barney's children are sorted in ascending order"+"\n"+ Arrays.toString(number));
System.out.println();
for(int i=0; i<= 9; i++)
sum = sum + number[i];
System.out.print("the average age is " + sum/10+"\n");
}
}

Re: Assignment please Help :(

Well, how would you do this "by hand" without a computer or code? Write out what you're trying to do, in English, in specific steps. Pretend you have a friend who has no idea how to figure out how many people are teenagers and how many are adults. When you have instructions that you could give to this friend, you'll have an algorithm that should be pretty easy to translate to code.