Professional Documents
Culture Documents
Recursion
Recursion
Recursion
Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(2,1);
}
}
Output:
2 5 8 11 14 17 20 23 26
1.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(2);
}
}
Output:
2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86
89 92 95 98
3.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(1);
}
}
Output:
1 2 4 8 16 32 64
4.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(1,1);
}
}
Output:
1 2 4 8 16 32 64 128 256 512
5.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(5,1);
}
}
Output:
5 10 15 20 25 30 35 40 45 50
6.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(1,1);
}
}
Output:
1 -2 3 -4 5 -6 7 -8 9 -10
7.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(1,1);
}
}
Output:-1 2 -3 4 -5 6 -7 8 -9 10
8.Code:
package com.company;
import java.util.*;
import java.lang.*;
Output:
0 1 1 2 3 5 8 13 21 34
9.Code:
package com.company;
import java.util.*;
import java.lang.*;
/* System.out.println("Enter");
int n = sc.nextInt();*/
meth(1,1);
}
}
Output:
1 11 111 1111 11111
10.Code:
package com.company;
import java.util.*;
import java.lang.*;
System.out.println("Enter");
int n = sc.nextInt();
if(meth(n,n/2))
System.out.println("Prime");
else
System.out.println("Not prime");
}
}
Output:Enter
7
Prime
11.Code:
package com.company;
import java.util.*;
import java.lang.*;
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
int i=0;
System.out.println(meth(n));
}
}
Output:
Enter
27
9
12.Code:
package com.company;
import java.util.*;
import java.lang.*;
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
int i=0;
System.out.println(meth(n));
}
}
Output:
Enter
27
14
15.Code:
package com.company;
import java.util.*;
import java.lang.*;
System.out.print(n%10);
meth(n/10);
}
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
meth(n);
}
}
Output:
Enter
245
542
16.Code:
package com.company;
import java.util.*;
import java.lang.*;
return 1+count(n/10);
}
}
public static int pow(int a,int b)
{
if(b==0)
return 1;
else
{
return a*pow(a,b-1);
}
}
public static int meth(int n,int c)
{
if(n==0)
return 0;
return pow(n%10,c)+meth(n/10,c);
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
int c=count(n);
int m =meth(n,c);
if(m==n)
System.out.println("Armstrong");
else
System.out.println("Not Armstrong");
}
}
Output:
Enter
153
Armstrong
17.Code:
package com.company;
import java.util.*;
import java.lang.*;
c=c*10+(n%10);
reverse(n/10);
}
return c;
}
public static boolean prime(int n,int i)
{
if(i>=2)
{
if(n%i==0)
return false;
prime(n,i-1);
}
return true;
}
public static int meth(int n)
{
if(prime(n,n/2))
{
int x=reverse(n);
if(prime(x,x/2))
{
return 1;
}
}
return 0;
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
if (meth(n)==1)
System.out.println("Emirp");
else
System.out.println("Not Emirp");
}
}
Output:
Enter
31
Emirp
18.Code:
package com.company;
import java.util.*;
import java.lang.*;
System.out.println("Enter");
int n = sc.nextInt();
if (meth(n)==n)
System.out.println("palindrome");
else
System.out.println("Not Palindrome");
}
}
Output
Enter
121
palindrome
19.Code:
package com.company;
import java.util.*;
import java.lang.*;
System.out.println("Enter");
int n = sc.nextInt();
System.out.println(meth(n));
}
}
Output:
Enter
111
3
20.Code:
package com.company;
import java.util.*;
import java.lang.*;
System.out.println("Enter");
int n = sc.nextInt();
System.out.println(meth(n));
}
}
Output:
Enter
45862
5
21.Code:
package com.company;
import java.util.*;
import java.lang.*;
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
meth(n,1);
}
}
Output:
Enter
24
1
2
3
4
6
8
12
24
22.Code:
package com.company;
import java.util.*;
import java.lang.*;
if(i==0)
return n;
return meth(i,n%i);
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
/*System.out.println("Enter");
int n = sc.nextInt();*/
System.out.println( meth(60,36));
}
}
Output:
12
23.Code:
package com.company;
import java.util.*;
import java.lang.*;
if (i==0)
return 1;
return n*meth(n,i-1);
}
public static void main(String[] args) {
// write your code here
// Characters pattern
Scanner sc = new Scanner(System.in);
System.out.println("Enter");
int n = sc.nextInt();
int i= sc.nextInt();
System.out.println( meth(n,i));
}
}
Output:
Enter
5 3
125