PROGRAM TO FIND THE SUM OF ARRAY USING RECURSION java
#1

Code:
import java.io.*;
class Arraysum
{
int temp;
      int sum(int a[],int n)
      {
            if(n==1)
                  return a[0];
            else
        {
                  temp =sum(a,n-1);
                   temp=temp+a[n-1];
                   return temp;
        }
       }
}
class Newarray
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
          System.out.println("Enter limit");
         int n=Integer.parseInt(dis.readLine());
         int a[]=new int[10];
         System.out.println("Enter the array");
    

for(int i=0;i<n;i++)
         {  
             a[i]=Integer.parseInt(dis.readLine());
         }
         Arraysum a1=new Arraysum();
         System.out.println("Array sum is"+ a1.sum(a,n));
}
}



OUTPUT
E:\5BCA-B\lijo\java>java Newarray
Enter limit
3
Enter the array
2
3
4
Array sum is 9


Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: recursive find largest array sum,
Popular Searches: find people by address, c program to find binomial coefficient using recursion, bb84 program code in java, nfa to dfa conversion program in java, help find the best, calculate the factorial of number using recursion and print the result, program for biodata in java,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Simple Key Events Java source code smart paper boy 3 3,646 07-02-2017, 03:41 PM
Last Post: NARESHLAFOOT
  VHDL program for Booth’s Multiplier smart paper boy 2 5,720 20-04-2013, 11:59 AM
Last Post: T
  Program in “LEX” to count number of vowels and consonants seminar class 2 9,684 22-03-2013, 10:20 AM
Last Post: computer topic
  Program in “LEX” to count number of Identifiers and Keywords seminar class 1 4,918 28-01-2013, 03:21 PM
Last Post: Guest
  Window Events Java source code smart paper boy 1 3,712 02-03-2012, 10:48 AM
Last Post: seminar paper
  Inter net banking java source code smart paper boy 3 6,006 01-03-2012, 11:24 AM
Last Post: seminar paper
  UDP server java source code smart paper boy 1 3,851 05-01-2012, 05:50 PM
Last Post: jeslinapeter
  UDP client Java source code smart paper boy 2 3,722 12-12-2011, 09:56 AM
Last Post: seminar addict
  Text Demo Java source code smart paper boy 0 2,102 30-08-2011, 12:44 PM
Last Post: smart paper boy
  Text Area Demo Java source code smart paper boy 0 2,113 30-08-2011, 12:44 PM
Last Post: smart paper boy

Forum Jump: