Pages

Showing posts with label using. Show all posts
Showing posts with label using. Show all posts

Wednesday, April 2, 2014

Java code to find the sum of the following series using recursion 1 2 2 2 3 2 n 2

/*
Program to find the sum of the following series using recursion :
12 + 22 + 32 +.......+ n2
*/

import java.io.*;
class series
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
series call = new series();
System.out.print("Enter value of n : ");
int n = Integer.parseInt(br.readLine());
System.out.println("Sum of series = " +call.sum(n));
}
int sum(int n)
{
if(n==1)
return 1;
else
return (n*n)+sum(n-1);
}
}


/**
* ALGORITHM :
* ---------
* 1. Start
* 2. Accept a number n from user.
* 3. Using method of recursion, add all the squared numbers upto n.
* 4. Print the sum.
* 5. End
*/

/*
OUTPUT :
------
Enter value of n : 5
Sum of series = 55
*/



Read More..

Monday, March 31, 2014

Back to Home Screen directly using ACTION MAIN with category CATEGORY HOME

If you want to go to Home Screen directly, using the code:


Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);



Read More..