Need help
NanaOhene_Nyark (3)

This program is meant to calculate the average of 3 numbers but i keep receiving errors that i don't know how to fix. the Language i used is java, if you could show me what I did wrong I would greatly appreciate it.

You are viewing a single comment. View All
Answered by Edgod (78) [earned 5 cycles]
View Answer
Edgod (78)

@NanaOhene_Nyark I have fixed the errors in your program, and did what I think you wanted to do. You can check it using this link (if you want):

Let me be more clear on what you didn't understand.
On your first line

import java.util.*;

you have imported a package that contains data in order to make this line work:

Scanner keyboard = new Scanner(;

There are packages in java that enable you to do certain tasks.

On number 3, when I recommended that you should use variables for sum and average, I meant:

int sum = a+b+c;
int average = sum/3;

Using variables can make your code easier to read, but it's up to you on how you want to write your code. By doing this, you can then use variables sum and average in your print statements.

What I've noticed is that in your code, is that you have some curly brackets { } that aren't needed. Over here:

public class main  { Lab2Averagejava


      public static void main(String[] args) {

Ignore the other errors in the first one, both lines only need one { after it, and one } at the end to close it.

By the way, Java is case sensitive, which means Main and main are two different words. You might be wondering why capitalization is important, but you will learn the reason later.

Just wondering, are you using any websites or documents to learn Java?