Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: My head Hurts... such a simple problem but I'm stuck!

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default My head Hurts... such a simple problem but I'm stuck!

    I'm supposed to do this program as an assignment and I think I'm completely stuck... Maybe it's because I have so much due for other classes and I'm looking at the problem in a different way ><.

    This is what we have to do :

    Create a program that asks the user to read in 10 integers and prints the maximum, the total and the average of the list of numbers to the screen.

    For example, if the user entered:

    10 12 16 13 4 5 21 2 6 1

    the maximum entered is 21, then total is 90 and the average (total divided by number of items in list) is 9.

    This is what I have so far
     
    import java.util.Scanner;
     
     
    public class LetterCounter {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    final int NUMCHARS = 10;
    Scanner scan = new Scanner(System.in);
    int[] numbers = new int[scan.nextInt()];
     
     
    System.out.print("Enter random Numbers:");
    scan.nextInt();
    for (int count= 0; count < NUMCHARS; count++)
    {
    System.out.print("Enter random Numbers:");
    scan.nextInt();
     
    }
     
     
     
     //results
    System.out.println("Total: "  ) ;
    System.out.println("Average: " );
     System.out.println("Highest Entered: ");
     
    	}
     
     
     
    	}

    Any help will be appreciated.
    Thanks.


  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: My head Hurts... such a simple problem but I'm stuck!

    Okay I was able to do the Total and Average.

    Now how will I be able to find the Highest number entered in the array list?
    This is my current code.

    import java.util.Scanner;
     
     
    public class LetterCounter {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    // Declare Variables
    Scanner scan = new Scanner(System.in); // scanner
    int[] numbers = new int[10]; //array for 
    //
     
     
     
    for (int count= 0; count < 10; count++)
    {
    System.out.print("Enter random Numbers:");
     
    numbers[count]= scan.nextInt();
    }
     
    int total;
    int average;
    int highest;
    total = numbers[0]+numbers[1]+numbers[2]+numbers[3]+ numbers[4]+numbers[5]+numbers[6]+numbers[7]+numbers[8]+numbers[9];
    average = total / numbers.length;
     
     
    //results
    System.out.println("Total: "+ total ) ;
    System.out.println("Average: "+average );
     System.out.println("Highest Entered: ");
     
    	}
     
     
     
    	}

  3. #3
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: My head Hurts... such a simple problem but I'm stuck!

    Use a variable to store the highest value. Set it to 0. For every number that comes in, compare it to the highest value variable and if it's bigger, set the highest value to the new value.

  4. The Following User Says Thank You to dlorde For This Useful Post:

    Kassino (May 9th, 2010)

  5. #4
    Junior Member
    Join Date
    May 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: My head Hurts... such a simple problem but I'm stuck!

    Thank you dlorde


    After 2~3 minutes I was able to come up with the solution . Don't know why I was stuck with such a simple problem, really. xD

    Final code
    import java.util.Scanner;
     
     
    public class LetterCounter {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    // Declare Variables
    Scanner scan = new Scanner(System.in); // scanner
    int[] numbers = new int[10]; //array for numbers 
    int currenthighest = 0; // integer for highest value stored in the array
     
     
     
     
    for (int count= 0; count < 10; count++)
    {
    System.out.print("Enter random Numbers:");
    numbers[count]= scan.nextInt();
    if (numbers[count]> currenthighest) //checks for highest number input
    {
    	currenthighest= numbers[count];
    }
    }
     
     
     
    int total;
    int average;
    total = numbers[0]+numbers[1]+numbers[2]+numbers[3]+ numbers[4]+numbers[5]+numbers[6]+numbers[7]+numbers[8]+numbers[9];
    average = total / numbers.length;
     
     
    //results
    System.out.println("Total: "+ total ) ;
    System.out.println("Average: "+average );
     System.out.println("Highest Entered: " +currenthighest);
     
    	}
     
     
    }

  6. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: My head Hurts... such a simple problem but I'm stuck!

    Congratulations on solving your issue. If you are complete, please mark this thread as solved

    http://www.javaprogrammingforums.com...ad-solved.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Simple Game In Java (Head and Tails).
    By drkossa in forum Java Theory & Questions
    Replies: 5
    Last Post: November 28th, 2009, 11:40 AM
  2. Simple import problem
    By Mekster in forum Java IDEs
    Replies: 3
    Last Post: November 13th, 2009, 09:17 PM
  3. Simple scanner problem
    By Sinensis in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 20th, 2009, 09:01 PM
  4. simple problem w/ appelets which i cant figure out
    By JavaGreg in forum Java Applets
    Replies: 7
    Last Post: August 15th, 2009, 07:22 PM
  5. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM