# Thread: Help compeleting four average mark.

1. Member
Join Date
Mar 2010
Posts
4
Rep Power
0

## Help compeleting four average mark.

Hello, I am new at java I am having a problem finishing my first assignment lol. I am trying to make a program that will take 4 marks and average them out. Looks easy sounds easy but not really lol.

Here is what I got so far.

Java Code:
```public static void main (String[] args)
{
c = new Console () ;
int x;
String i[] = new String[3] ;
c.printIn (“Four Courses Average Taker”) ;
for (x=0;x < 3;x++)
{
c.print (“Enter your first mark“) ;
}
c.printIn (“Your average for the four courses is```
the problem I am having is how to tell the program Enter the Second mark because i x is going to say to all the numbers

after doing that how do I tell it to average out.

any input will do more I learn different people better is for me. So give me anything I will try to understand. Thanks a lot YOUR THE BEST!!!
Last edited by lebron11; 03-08-2010 at 05:48 PM.

2. Uhm, you have four inputs, but only an array with three 'slots'.
Have a look at Integer.parseInt(String s)
How would you calculate an average on a piece of paper?

3. Member
Join Date
Mar 2010
Posts
4
Rep Power
0
I have three slots because I think 0 is a slot as well it will start from 0 1 2 3 that makes it four slots that;s why I have 3 there
Integer.parseInt (String s) i have no idea how to put that in there.
lol I like your last questions I would take 4 numbers 85+95+99+50=329/4=82.25 lol not rocket science.

4. Originally Posted by lebron11
I have three slots because I think 0 is a slot as well it will start from 0 1 2 3 that makes it four slots that;s why I have 3 there
Integer.parseInt (String s) i have no idea how to put that in there.
lol I like your last questions I would take 4 numbers 85+95+99+50=329/4=82.25 lol not rocket science.
False, String i[] = new String[3] is three slots [0,1,2].

Have you read the Integer API? How would you calculate numbers with having Strings only?

So you have to change the inserted number literals into numbers, add them up and divide them by four. And before you ask why your average calculation comes up with 82, think about datatypes and read this:
Using Variable Argument Lists and Some Things You Should Know About Floating-Point Arithmetic

5. Member
Join Date
Mar 2010
Posts
4
Rep Power
0
Your the best man thanks for explaining about the slots lol U got me there lol. Nope I have not read the integer API, ya your right I do need interger code in there. I will figure that out how get back to you so you can check the rest of it. I will read it and come back to you ASAP. THANKS alot for explaining YOUR THE BEST. PLease check in 9mins I will write you back on here.

6. Hmpf, calm down. I'll have a look in an hour :)

7. Member
Join Date
Mar 2010
Posts
4
Rep Power
0
lol I'm getting too excited lol. So here is another program

Java Code:
```Import java.util.Scanner;

Class apples{
Public static void main (String[] args) {
Scanner input = Scanner (system.in) ;
Int total = 0
Int average ;
Int counter = 0;

While (counter < 4) {
grade = input .nextInt () ;
total = total + grade ;
counter++;
}
average = total/4
System.out.printIn (“Your average is “+ average) ;
}
}```
Now this program is not using integer why? and they somehow manage to do it! I am just having a hard time doing it my way I don;t know how to add integer into my thing so it will read only numbers and then divide that number by 4 to get the average. Can you feed that in my table so I can see because there is no way I can do it my way. Maybe next year or never lol
Last edited by lebron11; 03-08-2010 at 06:51 PM.

8. That one doesn't even compile.

No, I won't change your program, that's your job. You won't learn anything by that. Do your best, post your code and ask specific questions when you're stuck.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•