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 7 of 7

Thread: Arrays

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    21
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Arrays

    import java.util.Scanner;  
    public class Max_Number {
      public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
     
        double[] myList = new double[6];
     
        double max = myList[0];
        for (int i = 1; i < myList.length; i++) {
          if (myList[i] > max) max = myList[i];
     
            System.out.print("Enter a number: ");
          myList[i] = input.nextDouble();
     
        }
     
     
        int countGreater = 0;
     
        for (int i = 0; i <myList.length; i++) {
            if(myList[i] > max)
            countGreater++;
        }
     
        System.out.println("The max is " + max);
        System.out.println("The number of values greater than the max is " + countGreater);
      }
    }
    The question asked me to write a program that reads 5 numbers, computes the max and finds out how many numbers are above the max. Please help!!!!!!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Arrays

    With what?
    Improving the world one idiot at a time!

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Arrays

    Quote Originally Posted by ruffu054 View Post
    computes the max and finds out how many numbers are above the max.
    Simple. None!

    How can you have any numbers greater than the max number?
    Improving the world one idiot at a time!

  4. #4
    Junior Member
    Join Date
    Aug 2011
    Posts
    21
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    Its not giving me the correct output when run the program.

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    21
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    I dont make up the problem I just try to do them

  6. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    21
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    still confused?????????????

  7. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Arrays

    Then I suggest you seek clarification from your teacher. Given the numbers: 1 6 4 2, the largest number is 6 and there are no numbers bigger than 6. So the question does not make sense or you have misunderstood it.
    Improving the world one idiot at a time!

Similar Threads

  1. Help with arrays
    By mike2452 in forum Collections and Generics
    Replies: 6
    Last Post: August 6th, 2011, 12:15 PM
  2. 3 Arrays
    By D3158 in forum Collections and Generics
    Replies: 27
    Last Post: June 16th, 2011, 11:10 AM
  3. arrays
    By dwamalwa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2010, 01:44 AM
  4. Arrays
    By mlan in forum Java Theory & Questions
    Replies: 2
    Last Post: February 26th, 2010, 10:23 AM
  5. 2d Arrays
    By mgutierrez19 in forum Collections and Generics
    Replies: 5
    Last Post: October 27th, 2009, 04:08 PM