# util scanner with array

• 03-07-2011, 03:54 AM
Raymondster
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..
• 03-07-2011, 04:48 AM
Eranga
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,

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.
• 03-20-2011, 05:48 AM
nap_patague
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

}
• 03-23-2011, 09:34 AM
Eranga
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.