Results 1 to 4 of 4
  1. #1
    Raymondster is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Lightbulb 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. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,374
    Blog Entries
    1
    Rep Power
    18

    Default

    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. #3
    nap_patague is offline Member
    Join Date
    Mar 2011
    Location
    Bulacan, Philippines
    Posts
    23
    Rep Power
    0

    Default

    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. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,374
    Blog Entries
    1
    Rep Power
    18

    Default

    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.

Similar Threads

  1. java.util.Scanner runs in Vista but not in Linux
    By pellebye in forum New To Java
    Replies: 6
    Last Post: 08-24-2009, 03:50 AM
  2. java.util.Scanner not recognised
    By pjm35@st-and.ac.uk in forum New To Java
    Replies: 4
    Last Post: 06-07-2008, 03:32 PM
  3. Replies: 0
    Last Post: 11-20-2007, 04:59 PM
  4. Using ava.util.Scanner
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-20-2007, 04:47 PM
  5. The import java.util.Scanner cannot be resolved
    By Heather in forum Advanced Java
    Replies: 1
    Last Post: 07-08-2007, 01:05 AM

Posting Permissions

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