1. Member
Join Date
Mar 2011
Posts
1
Rep Power
0

util scanner with array

can you give me a more explanation of this?

how can I lope the average of 5 numbers?
example:

import java.util.Scanner;

public class average {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

Scanner inputData = new Scanner(System.in);
System.out.println("Enter a number");
int number = inputData.nextInt();
int[]num = new int [5];
int counter;
int ave = 0;

can you give me the whole program.....please...
I am a beginner student....healp me...please..

2. If you are a beginner, then start from the basic step. Lets start from the collecting user inputs. So how you can ask user to enter a number 5 times. You've to do something in a loop,

Java Code:
```while(...) {
// Body of the loop
}```
So how you decide the loop runs 5 times and ask the question. Forget about what to do with user inputs at the moment. Give a try and let me know.

3. Member
Join Date
Mar 2011
Location
Bulacan, Philippines
Posts
23
Rep Power
0
import java.util.Scanner;

public class average {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

Scanner inputData = new Scanner(System.in);
int[]num = new int [5];
for(int x=0;x<num.length;x++){
System.out.println("Enter a number");
int number = inputData.nextInt();
}

do the logic on your here

}

4. And you've to think about a way to store collected data from the user as well. That's all explains that your logic should be inside the loop or not.

Posting Permissions

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