10 Replies Latest reply: Aug 27, 2008 9:25 PM by 807589 RSS

    array program,, need help

    807589
      How do i make a array program with this requirements?

      "Input ten decimal values from the user. Find the sum and average of the data. Find the smallest value and the largest value. Display these four results to standard output using System.out."
      "public static final int NUMITEMS = 10;"

      i think i probably can make sum,avg,max,min program, but i dont know how to do a program for getting values from user and insert that program into the whole program...

      also, do i need 2 classes for that assignment?
        • 1. Re: array program,, need help
          807589
          try this
          DataInputStream in = new DataInputStream(System.in);
                         System.out.print("Enter number : ");
                         n=Int.parseInt(in.readLine());
          • 2. Re: array program,, need help
            807589
            I'd recommend Scanner instead of DataInputStream, as Scanner is especially intended for this sort of stuff.
            • 3. Re: array program,, need help
              807589
              then,, how do i use the "scanner scan"?
              • 4. Re: array program,, need help
                800282
                9491 wrote:
                then,, how do i use the "scanner scan"?
                Have a look at the API documentation of the Scanner class:
                [http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html]
                it also has some examples of how to use it in your code.

                Good luck.
                • 5. Re: array program,, need help
                  800313
                  this seems to be a very common question recently, enter numbers into array and output the max/min/average values

                  if you search the "new to java" section im sure you find some nearly complete code for your task!

                  Calypso
                  • 6. Re: array program,, need help
                    807589
                    Well done calypso!

                    Nothing like teaching people to copy other people's code instead of understanding and writing their own.
                    People like you should be shot.
                    • 7. Re: array program,, need help
                      800313
                      >
                      Well done calypso!

                      Nothing like teaching people to copy other people's code instead of understanding and writing their own.
                      People like you should be shot.>
                      When i was first starting out I found I could write the process down on paper but I didnt know the appropriate syntax and spent a long time trying to get it right. I found it much easier to look at working code and study it, then apply it to my situation

                      By looking at previous posts im sure the OP will see he/she had lots of similar problems to the others and will be able to read how they all were resolved.

                      Im sure the OP realises that copying code will not get them anywhere as they will surely fail their exams / job interviews and instead will just use the code as a reference and to study!
                      • 8. Re: array program,, need help
                        807589
                        calypso wrote:
                        Im sure the OP realises that copying code will not get them anywhere as they will surely fail their exams / job interviews and instead will just use the code as a reference and to study!
                        You have more faith in the humanity than me then...
                        • 9. Re: array program,, need help
                          JoachimSauer
                          -Kayaman- wrote:
                          calypso wrote:
                          Im sure the OP realises that copying code will not get them anywhere as they will surely fail their exams / job interviews and instead will just use the code as a reference and to study!
                          You have more faith in the humanity than me then...
                          Unfortunately there's a lot more evidence on this forum supporting Kayamans view, than there is supporting calypsos ...
                          • 10. Re: array program,, need help
                            807589
                            cross posted