Do not miss any new update

How to sum of Elements in an Array without Second Variable

Posted by aamir khan





Here We Are with a simple JAVA program that will print sum of  given Integer Elements without Second Variable......

Below is your Program
    // @author Aamir khan
    // @url aamir-4u.blogspot.com
    public class ArrayAdditon {
    public static void main(String args[]){
    int add[]={1,2,3,4,5,45,67,45,78,89,90};
    int i;
    for(i=0;i<add.length;i++){
       try{
        add[i]+=add[i+1];
        add[i+1]=add[i];
       } catch (Exception e) {
         }
        }
       System.out.println("Total = "+add[add.length-1]);
     }
    }
Result:- Total = 429

Download the Code from here

{ 0 comments... read them below or add one }

Post a Comment

What you Says

..-

Related Posts Plugin for WordPress, Blogger...

If you like this blog,then link back to me.
This is what you will see.



Optionally use this Widget installer to add this link to your blogger blog.