0% found this document useful (0 votes)
8 views13 pages

Computer Class 11 Programing

The document contains various Java programs demonstrating recursive techniques for tasks such as reversing words, converting decimal numbers to binary, octal, and hexadecimal, checking for Armstrong and perfect numbers, and identifying palindromes. Each program includes user input prompts and outputs results based on the computations performed. Overall, it serves as a practical guide for implementing recursion in programming.

Uploaded by

adhyantaparia001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

Computer Class 11 Programing

The document contains various Java programs demonstrating recursive techniques for tasks such as reversing words, converting decimal numbers to binary, octal, and hexadecimal, checking for Armstrong and perfect numbers, and identifying palindromes. Each program includes user input prompts and outputs results based on the computations performed. Overall, it serves as a practical guide for implementing recursion in programming.

Uploaded by

adhyantaparia001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

COMPUTER CLASS 11 PROGRAMING

WORD REVERSE
import java.util.*;
class rec
{
void Reverse(String y,int l)
{

if(l==-1)
return;

System.out.print(y.charAt(l));

Reverse(y,--l);
}
public static void main()
{
Scanner sc=new Scanner(System.in);
String x;int m;
rec obj=new rec();
System.out.println("Enter a word");
x=sc.nextLine();
m=x.length();
obj.Reverse(x,m-1);

}
}
WORD REVERSE
import java.util.*;
class word
{
void recursive(String a , int l)
{
if(l==-1)
return;
System.out.println(a.charAt(l));
recursive(a,--l);
}
public static void main()
{
word obj = new word();
Scanner sc = new Scanner (System.in);
String x;
int k;
System.out.println("Enter a string");
x=sc.nextLine();
k=x.length();
obj.recursive(x,k);
}
}
RECURSIVE MIXED PROGRAM
import java.util.*;
class deci_binary_recursive
{
int r,g,c,j,h=0;
void reverse_recursive(int w)
{
if(w>9)
reverse_recursive(w/10);

System.out.println(w%10);
}

void sum_recursive(int w)
{
if(w>9)
sum_recursive(w/10);
else
{
j=w%10;
h=h+j;
System.out.println(+h);
}
}

void deci_binary_recursive(int x)
{
if(x!=1)
deci_binary_recursive(x/2);

System.out.print(x%2);
}

void deci_octal_recursive(int y)
{
if(y>7)
deci_octal_recursive(y/8);

System.out.print(y%8);
}

void deci_hexadecimal_recursive(int z)
{
if(z>15)
deci_hexadecimal_recursive(z/16);
c=z%16;
if(c==10)
System.out.print("A");
else if(c==11)
System.out.print("B");
else if(c==12)
System.out.print("C");
else if(c==13)
System.out.print("D");
else if(c==14)
System.out.print("E");
else if(c==15)
System.out.print("A");
else
System.out.print(+c);
}

void number(int c)
{
if(c!=0)
r=g%10;
number(c/10);
}

public static void main()


{
Scanner sc = new Scanner (System.in);
deci_binary_recursive obj= new deci_binary_recursive();
int a,b,c,d;
System.out.println("Enter a decimal number");
a=sc.nextInt();
System.out.print("The binary equavelent is:- ");
obj.deci_binary_recursive(a);
System.out.println();
System.out.println("Enter a decimal number");
b=sc.nextInt();
System.out.print("The octal equavelent is:- ");
obj.deci_octal_recursive(b);
System.out.println();
System.out.println("Enter a decimal number");
c=sc.nextInt();
System.out.print("The hexadecimal equavelent is:- ");
obj.deci_hexadecimal_recursive(c);
System.out.println();
System.out.println("Enter a number");
d=sc.nextInt();
System.out.print("The digits of the number are:- ");
System.out.println();
obj.reverse_recursive(d);
}
}

RECURSIVE MIXED PROGRAM 2


import java.util.*;
class Recursive
{int s=0,k=0,r;
int factorial (int n)
{
if(n==1)
return 1;
return (n * factorial (n-1));
}

int armstrong (int x)


{
if(x==0)
return s;
r=x%10;
s=s+r*r*r;
return armstrong (x/10);
}

int pallindrome (int g)


{
if(g==0)
return k;
r=g%10;
k=k+r*10;
return pallindrome (g/10);
}

public static void main ()


{
Recursive obj = new Recursive();
Scanner sc = new Scanner (System.in);
int x,y,u,f,g,j,m,n,a=0;
System.out.println("Enter a number");
x=sc.nextInt();
a=obj.factorial(x);
System.out.println("The factorial is " +a);
System.out.println("Enter a number to be checked");
f=sc.nextInt();
u=obj.armstrong(f);
if(u==f)
System.out.println("The number is armstrong");
else
System.out.println("The number is not armstrong");
System.out.println("Enter a number to be checked");
g=sc.nextInt();
j=obj.pallindrome(g);
if(j==g)
System.out.println("The number is not pallindrome");
else
System.out.println("The number is pallindrome");
}
}
WORD REVERSE USING RECURSIVE
import java.util.*;
class word_rev
{
public static void main()
{
Scanner sc = new Scanner (System.in);
String x , y="";
int i,l;
char ch;
System.out.println("Enter a string");
x=sc.nextLine()+" ";
l=x.length();
for(i=0;i<l;i++)
{
ch=x.charAt(i);
if(ch!=' ')
{
y=ch+y;
}
else
{
System.out.print(y+" ");
y="";
}
}
}
}
FREQUENCY
import java.util.*;
class frequency
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int x,y,z,i,j,k,f;
f=0;
System.out.println("Enter the limit of the array");
int n=sc.nextInt();
int arr[] = new int[n];
System.out.println("Enter the array elements");
for(i=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
for(i=0;i<n;i++)
{
int c=0;
for(j=i;j<n;j++)
{
if(arr[i]==arr[j])
{
c++;
}
}
if(c==1)
{
f=0;
for(k=i;k>=0;k--)
{

if(arr[i]==arr[k])
{
f++;
}

}
System.out.println("The frequency of "+arr[i]+" is "+f);

}
}
}
}
ARRAY PROGRAM 1
import java.util.*;
class Arrays_1
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int arr[]= new int[10];
int x,y,s;
System.out.println("Enter the elements of the array");
for(int i=0;i<10;i++)
{
arr[i] = sc.nextInt();
}
System.out.println ("The enterd Array elements are:-");
s=0;
for(int i=0;i<10;i++)
{
s=s+arr[i];
System.out.print(arr[i]);
}
System.out.println("The sum of the elements of the entered array is" +s);
}
}
NAME
import java.util.*;
class Name
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int l,i,c=0;
String x,y;
char ch;
System.out.println("Enter your full name.");
x=sc.nextLine();
y=x.toUpperCase();
l=y.length();
for(i=0;i<l;i++)
{
ch=y.charAt(i);
if (ch==' ')
{
System.out.print((y.charAt(c))+". ");
c=i+1;
}

}
System.out.print(y.substring(c));
}
}
PERFECT NUMBER
import java.util.*;
class Perfect
{
public static void maim()
{
Scanner sc = new Scanner (System.in);
int x,r,y,s=0;
System.out.println("Enter a number to be checked");
x=sc.nextInt();
y=x;
for(int i=1;i<y;i++)
{
if (y%i==0)
s+=i;
}
if (s==x)
System.out.println("The number is an Perfect Number");
else
System.out.println("The number is not an Perfect number");
}
}
SADDLE NUMBER
import java.util.*;
class Saddle_Number
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int arr[][] = new int[4][4];
int rmin=0;
int cmax=0;
int i,j,k,l,x;
System.out.println("Enter the numbers");
for( i=0;i<4;i++)
{
for( j=0;j<4;j++)
{
arr[i][j]= sc.nextInt();
}
}
for( i=0;i<4;i++)
{
rmin=arr[i][0];
x=0;
for( j=0;j<4;j++)
{
if(arr[i][j]<rmin)
{
rmin=arr[i][j];
x=j;
}
cmax=arr[0][x];
for(k=0;k<4;k++)
{
if(arr[k][x]>cmax)
{
cmax=arr[k][x];
}
}

}
}
if(cmax==rmin)
System.out.println("The saddle point exists");
else
System.out.println("The saddle point does not exists");
}
}
DECIMAL TO BINARY
import java.util.*;
class Decimal_Binary
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int x,y,r,j,i=1;
int arr[]=new int[100];
System.out.println("Enter a decimal number");
x=sc.nextInt();
y=x;
while(y>0)
{
r=y%2;
arr[i]=r;
i++;
y=y/2;
}
for(j=i-1;j>=0;j--)
{
System.out.println(arr[j]);
}
}
}
ARMSTRONG SECOND METHOD
import java.util.*;
class Armstrong2
{
public static void maim()
{
Scanner sc = new Scanner (System.in);
int x,r,y,t,s=0;
System.out.println("Enter a number to be checked");
x=sc.nextInt();
y=x;
while(y>0)
{
t=y/10;
r=y-t*10;
s=s+r*r*r;
y=t;
}
if (s==x)
System.out.println("The number is an Armstrong Number");
else
System.out.println("The number is not an Armstrong number");
}
}
DECIMAL TO OCTAL
import java.util.*;
class Decimal_Octal
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int x,y,r,j,i=1;
int arr[]=new int[100];
System.out.println("Enter a decimal number");
x=sc.nextInt();
y=x;
while(y>0)
{
r=y%8;
arr[i]=r;
i++;
y=y/8;
}
for(j=i-1;j>=0;j--)
{
System.out.print(arr[j]);
}
}
}
MAGIC NUMBER
import java.util.*;
class Magic
{
public static void maim()
{
Scanner sc = new Scanner (System.in);
int x,r,y,s=0;
System.out.println("Enter a number to be checked");
x=sc.nextInt();
y=x;
while(y>9)
{
while(y>0)
{
r=y%10;
s=s+r;
y=y/10;
}
y=s;
}
if (s==1)
System.out.println("The number is an Magic Number");
else
System.out.println("The number is not an Magic number");
}
}
CONSECUTIVE NUMBER
import java.util.*;
class consecutive
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int x,y,i,j,k,s;
System.out.println("Enter a number");
x=sc.nextInt();
for(i=1;i<14 ;i++)
{
s=0;
for(j=i;j<=14;j++)
{
s=s+j;
if(s==x)
{
for(k=i;k<=j;k++)
{
System.out.print(k+", ");
}
System.out.println();
}
if(s>=x)
break;
}
}
}
}
DECIMAL TO HEXADECIMAL
import java.util.*;
class Decimal_Hexadecimal
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int x,y,r,j,i=1;

char arr[]=new char[100];


System.out.println("Enter a decimal number");
x=sc.nextInt();
y=x;
while(y>0)
{
r=y%16;
i++;
y=y/16;
}
for(j=i-1;j>=0;j--)
{
switch(arr[j])
{
case 10:
System.out.print(" A ");
break;
case 11:
System.out.print(" B ");
break;
case 12:
System.out.print(" C ");
break;
case 13:
System.out.print(" D ");
break;
case 14:
System.out.print(" E ");
break;
case 15:
System.out.print(" F ");
break;
default:
System.out.print(" "+arr[j]+" ");
break;
}
}
}
}
PALLINDROME
import java.util.*;
class Pallindrome
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int x,y,r,s=0;
System.out.println("Enter a number");
x=sc.nextInt();
y=x;
while(y>0)
{
r=y%10;
s=s*10+r;
y=y/10;
}
if(s==x)
System.out.println("The number is pallindrome");
else
System.out.println("The number is not pallindrome");
}
}

You might also like