aspose file tools*
The moose likes Beginning Java and the fly likes summing elements of array and getting strange behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "summing elements of array and getting strange behavior" Watch "summing elements of array and getting strange behavior" New topic
Author

summing elements of array and getting strange behavior

Bill Suttle
Ranch Hand

Joined: Oct 22, 2012
Posts: 37
Hi,

Ok, this isn't a school assignment...just a random exercise I found on the internet since I'm beginning to learn a bit about arrays. For my version, user enters the number of indexes the array will have, and then enters data for the elements, and we output the sum. The sort of tricky part (part of the exercise I suppose is thinking about primitive variables) is that the input for elements should be a char representing a single integer and output should be in terms of a long. Again, not really sure why because I would not go about the task this way...but I want to complete the exercise per instructions as a learning experience.

The program below compiles fine. However, let's say I chose 1 index for my array, and enter 1 as my element..the program returns 49. If I chose 1 index and enter 2 as my element, it returns 50...and so on according to pattern. My question is first can you point me in the direction of where I'm going wrong? Second, I guess this is more theoretical, any ideas for why it is beginning at 49?

Here is my code:



Thanks in advance for your help
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 72

It's giving the Ascii char value.

http://www.asciitable.com/


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Bill Suttle
Ranch Hand

Joined: Oct 22, 2012
Posts: 37
Awesome Aj, thanks!

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: summing elements of array and getting strange behavior