Qdoc - Tips Raghu Sir Jspiders Programs
Qdoc - Tips Raghu Sir Jspiders Programs
Qdoc - Tips Raghu Sir Jspiders Programs
No System
import java.util.Scanner;
int count=0;
while(n>0){
if(n%2==1){
count++;
n=n/2;
return count;
}
System.out.println("enter
System.out.println("enter the no");
int n=sc.nextInt();
int s=countbits(n);
Output
enter the no
the no of bits 3
import java.util.Scanner;
while(n>9){
int sum=0;
while(n!=0){
int r=n%10;
sum=sum+r*r;
n=n/10;
n=sum;
return n==1||n==7;
System.out.println("Happy
System.out.println("Happy nos are");
for(int i=1;i<=n;i++){
if(ishappy(i)){
}
}
int count=0;
for(int i=1;i<=n;i++){
if(ishappy(i)){
count++;
return count;
int sum=0;
for(int i=1;i<=n;i++){
if(ishappy(i)){
sum=sum+i;
return sum;
int n=sc.nextInt();
boolean b=ishappy(n);
if(b)
System.out.println("Happy no");
else
happyno(n);
int cnt=counthappy(n);
System.out.println("\ntotal
System.out.println("\ntotal happy are "+cnt);
int sm=sumhappy(n);
System.out.println("total
System.out.println("total happy are "+sm);
output
Enter the no
21
Not happy no
1 7 10 13 19
number conversion
import java.util.Scanner;
int dec=0;
int c=0;
while(n!=0){
int r=n%10;
dec=dec+r*pow(2,c);
c++;
n=n/10;
return dec;
}
static int pow(int n, int c) {
int pw=1;
while(c>0)
pw=pw*n;
c--;
return pw;
System.out.println("Enter
System.out.println("Enter the no ");
int n=sc.nextInt();
int bd=bintodec(n);
System.out.println("The no is = "+bd);
output:-
Enter the no
111
The no is = 7
as(2+4+1)
String bin="";
while(n>0){
int r=n%2;
bin=r+bin;
n=n/2;
return bin;
System.out.println("Enter
System.out.println("Enter the no");
int n=sc.nextInt();
String bin=dectobin(n);
output
Enter the no
13
import java.util.Scanner;
String hx="";
while(n>0){
int r=n%16;
if(r<10){
hx=r+hx;
else
hx=(char)(r+55)+hx;
//hx=(char)(r+87)+hx;
n=n/16;
return hx;
System.out.println("Enter
System.out.println("Enter the no");
int n=sc.nextInt();
String octa=dectohex(n);
System.out.println("the
System.out.println("the hexadecimal is = "+octa);
}
output
Enter the no
12
the hexadecimal is = C
import java.util.Scanner;
String oct="";
while(n>0){
int r=n%8;
oct=r+oct;
n=n/8;
}
return oct;
System.out.println("Enter
System.out.println("Enter the no");
int n=sc.nextInt();
String oct=dectooct(n);
System.out.println("the
System.out.println("the binary of "+n+" is "+oct);
o/p:-
Enter the no
12
the binary of 12 is 14
==============================
write a program to check no is even or odd without
using loop
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the integer : ");
int no=key.nextInt();
String str[]={"Even","Odd"};
str[]={"Even","Odd"};
o/p:-
4 is Even Number
Array Class
1d array
***************
write a program
program to perform
perform sum of array
array and average
average
of elements of array
package onedimensionarry;
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the size of array");
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter "+n+" Elements of Array ");
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
double sum=0.0;
for(int i=0;i<arr.length;i++){
i=0;i<arr.length;i++){
sum=sum+arr[i];
System.out.println("sum
System.out.println("sum of "+n+" arrays are = "+sum);
o/p:-
12478
package onedimensionarry;
import java.util.Scanner;
double sum=0.0;
for(int i=0;i<a.length;i++){
i=0;i<a.length;i++){
sum=sum+a[i];
return sum;
int[]readArr(){
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter "+n+" Elements of Array");
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
ar[i]=sc.nextInt();
return ar;
for(int i=0;i<ele.length;i++){
i=0;i<ele.length;i++){
System.out.print(ele[i]);
if(i<ele.length-1){
System.out.print(",");
System.out.println();
}
//Get the Biggest Array elements//
int big=ar[0];
for(int i=1;i<ar.length;i++){
i=1;i<ar.length;i++){
if(ar[i]>big)
big=ar[i];
return big;
int ar[]=ao.readArr();
System.out.print("Entered
System.out.print("Entered elemnts are\n");
ao.dispArr(ar);
int k=ao.getBiggest(ar);
k=ao.getBiggest(ar);
System.out.println("Biggest
System.out.println("Biggest element is = "+k);
double sum=ao.sumOfArray(ar);
sum=ao.sumOfArray(ar);
13567
1,3,5,6,7
Biggest element is = 7
package onedimensionarry;
import java.util.Scanner;
public class CountEleArray {
int n=ar.length;
int count=1;
if(ar[i]==ar[j]){
count++;
ar[j]=ar[n-1];
n--;
j--;
int n=sc.nextInt();
arr[i]=sc.nextInt();
countEle(arr);
o/p:-
1356
no of occurence of 1->1
no of occurence of 3->1
no of occurence of 5->1
no of occurence of 6->1
package onedimensionarry;
import java.util.Scanner;
int pc=0;
if(isprime(a[i]))
pc++;
return pc;
int i=2;
while(i<=n/2){
if(n%i==0)
return false;
i++;
return true;
System.out.println("Enter
System.out.println("Enter the no of array");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the elements");
ar[i]=sc.nextInt();
int count=pc.countPrime(ar);
}
o/p:-
1467
no of prime element is 2
package onedimensionarry;
import java.util.Scanner;
int[] readArr()
System.out.println("Enter
System.out.println("Enter How many integer value you want");
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter the values");
for(int i=0;i<arr.length;i++)
i=0;i<arr.length;i++)
{
arr[i]=sc.nextInt();
return arr;
for(int i=0;i<ele.length;i++)
i=0;i<ele.length;i++)
System.out.print(ele[i]);
if(i<ele.length-1)
System.out.print(",");
System.out.println("even
System.out.println("even and odd values are ");
for(int i=0;i<a.length;i++)
i=0;i<a.length;i++)
{
count[a[i]%2]++;
return count;
int arr[]=eo.readArr();
int[] evod=eo.countEvOd(arr);
evod=eo.countEvOd(arr);
eo.dispArr(evod);
o/p:-
278
2,1
import java.util.Scanner;
int[]readArr(){
System.out.println("Enter
System.out.println("Enter the size of array");
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter "+n+" Elements of Array ");
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
ar[i]=sc.nextInt();
return ar;
for(int i=0;i<ele.length;i++){
i=0;i<ele.length;i++){
System.out.print(ele[i]);
if(i<ele.length-1){
System.out.print(",");
System.out.println();
int small=ar[0];
for(int i=1;i<ar.length;i++){
i=1;i<ar.length;i++){
if(ar[i]<small)
small=ar[i];
return small;
int ar[]=ao.readArr();
System.out.print("Entered
System.out.print("Entered elemnts are ");
ao.dispArr(ar);
int k=ao.getsmallest(ar);
k=ao.getsmallest(ar);
System.out.println("Smallest
System.out.println("Smallest element is "+k);
o/p:-
1467
Smallest element is 1
package onedimensionarry;
import java.util.Scanner;
for(int i=0;i<=ar.length/2;i++){
i=0;i<=ar.length/2;i++){
int t=ar[i];
ar[i]=ar[ar.length-1-i];
ar[ar.length-1-i]=t;
System.out.println("reverse
System.out.println("reverse elements");
System.out.print(ar[i]+"" ");
System.out.print(ar[i]+
System.out.print("Entered
System.out.print("Entered elemnts are ");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the elements");
ar[i]=sc.nextInt();
rc.reversearray(ar);
}
}
o/p:-
2467
reverse elements
7462
package onedimensionarry;
import java.util.Scanner;
int count=0;
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
if(ar[i]>0)
count++;
}
return count;
int count1=0;
for(int i=0;i<arr.length;i++){
i=0;i<arr.length;i++){
if(arr[i]<0)
count1++;
return count1;
System.out.print("enter
System.out.print("enter the no of elements of array");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the elements");
ar[i]=sc.nextInt();
}
int count=ao.getpositive(ar);
count=ao.getpositive(ar);
System.out.println("Positive
System.out.println("Positive element is "+count);
int count1=ao.getnegative(ar);
count1=ao.getnegative(ar);
System.out.println("Negative
System.out.println("Negative element
element is "+count1);
o/p:-
2 4 6 8 -3 -5
Positive element is 4
Negative element is 2
package onedimensionarry;
import java.util.Scanner;
public class InsertEle {
if(index<0||index>arr.length){
System.out.println("index
System.out.println("index not in range");
return arr;
na[index]=ele;
for(int i=0;i<arr.length;i++){
i=0;i<arr.length;i++){
if(i<index)
na[i]=arr[i];
else
na[i+1]=arr[i];
return na;
System.out.println("Enter
System.out.println("Enter the array size");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the element");
int arr[]=new int[n];
arr[i]=sc.nextInt();
System.out.println("enter
System.out.println("enter element");
int ele=sc.nextInt();
System.out.println("enter
System.out.println("enter position");
int index=sc.nextInt();
arr=insert(arr,ele,index);
sc.close();
System.out.print(arr[i]+"" ");
System.out.print(arr[i]+
o/p:-
enter element
enter position
15769
package onedimensionarry;
import java.util.Scanner;
if(index<0||index>arr.length){
return arr;
for(int i=0;i<na.length;i++){
i=0;i<na.length;i++){
if(i<index)
na[i]=arr[i];
else
na[i]=arr[i+1];
return na;
System.out.println("Enter
System.out.println("Enter the array size");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the element");
arr[i]=sc.nextInt();
int index=sc.nextInt();
arr=delete(arr,index);
sc.close();
System.out.println("The new elemnts");
System.out.print(arr[i]+"
System.out.print(arr[i]+" ");
o/p:-
257
27
package onedimensionarry;
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the array size");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the element");
arr[i]=sc.nextInt();
int h1=arr[0];
int h2=arr[1];
if(h1<arr[i]){
h2=h1;
h1=arr[i];
}
else if(arr[i]>h2&&h1!=arr[i]){
if(arr[i]>h2&&h1!=arr[i]){
h2=arr[i];
System.out.println("2nd
System.out.println("2nd biggest = "+h2);
o/p:-
14689
1st biggest = 9
2nd biggest = 8
package onedimensionarry;
import java.util.Scanner;
public class FirsttwoLeast {
System.out.println("Enter
System.out.println("Enter the array size");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the element");
arr[i]=sc.nextInt();
int l1=arr[0];
int l2=arr[1];
if(l1>arr[i]){
l2=l1;
l1=arr[i];
else if(arr[i]<l2&&l1!=arr[i]){
if(arr[i]<l2&&l1!=arr[i]){
l2=arr[i];
}
System.out.println("2nd
System.out.println("2nd least = "+l2);
o/p:-
2719
1st least = 1
2nd least = 2
package onedimensionarry;
import java.util.Scanner;
public class WithoutCompareCountEle {
System.out.println("Enter
System.out.println("Enter the size of array");
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter the elemts");
arr[i]=sc.nextInt();
countElement(arr);
int big=arr[0];
for(int i=0;i<arr.length;i++){
i=0;i<arr.length;i++){
if(big<arr[i])
big=arr[i];
c[arr[i]]++;
for(int i =0;i<c.length;i++){
=0;i<c.length;i++){
if(c[i]>0)
System.out.println(i+"-->"+c[i]);
o/p:-
1 5 86
1-->1
5-->1
7-->1
86-->1
Write a program to perform union operation with two
two array
package onedimensionarry;
import java.util.LinkedHashSet;
java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
us.add(a[i]);
for(int i=0;i<b.length;i++){
i=0;i<b.length;i++){
us.add(b[i]);
int i=0;
for(Integer ele:us){
ar[i]=ele;
i++;
return ar;
System.out.println("enter
System.out.println("enter the no of value for 1st array");
int n1=sc.nextInt();
System.out.println("enter
System.out.println("enter the value");
a[i]=sc.nextInt();
}
System.out.println("enter
System.out.println("enter the no of value for 2nd array");
int n2=sc.nextInt();
System.out.println("enter
System.out.println("enter the value");
b[i]=sc.nextInt();
int [] ar=union(a,b);
System.out.print(ar[i]+"" ");
System.out.print(ar[i]+
o/p:-
4
enter the value
1356
468
135648
package onedimensionarry;
import java.util.LinkedHashSet;
java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
for(int j=0;j<b.length;j++)
if(a[i]==b[j]){
f=0;
break;
if(f==1)
ms.add(a[i]);
int i=0;
for(Integer in:ms){
c[i]=in;
i++;
return c;
int n1=sc.nextInt();
System.out.println("enter
System.out.println("enter the value");
a[i]=sc.nextInt();
System.out.println("enter
System.out.println("enter the no of value for 2nd array");
int n2=sc.nextInt();
System.out.println("enter
System.out.println("enter the value");
b[i]=sc.nextInt();
int [] ar1=Minus(a,b);
if(ar1[i]!=0)
System.out.println(ar1[i]+"
System.out.println(ar1[i]+" ");
}
System.out.println("==========
System.out.println("====================
===========");
=");
int [] ar2=Minus(b,a);
if(ar2[i]!=0)
System.out.print(ar2[i]+"
System.out.print(ar2[i]+" ");
sc.close();
o/p:-
157
=====================
48
Write a program
p rogram to perform intersection operation
package onedimensionarry;
import java.util.LinkedHashSet;
java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
for(int j=0;j<b.length;j++){
j=0;j<b.length;j++){
if(a[i]==b[j])
ar[i]=a[i];
}
return ar;
for(int j=0;j<b.length;j++){
j=0;j<b.length;j++){
if(a[i]==b[j])
is.add(a[i]);
int i=0;
for(Integer in:is){
c[i]=in;
i++;
return c;
}
System.out.println("enter
System.out.println("enter the no of value for 1st array");
int n1=sc.nextInt();
a[i]=sc.nextInt();
System.out.println("enter
System.out.println("enter the no of value for 2nd array");
int n2=sc.nextInt();
System.out.println("enter
System.out.println("enter the value");
b[i]=sc.nextInt();
int [] ar1=interSection2(a,b);
ar1=interSection2(a,b);
System.out.println("the result array is");
if(ar1[i]!=0)
System.out.print(ar1[i]+"
System.out.print(ar1[i]+" ");
sc.close();
o/p:-
3578
4253
35
Write a program to merge two array
package onedimensionarry;
import java.util.Scanner;
for(int i=0;i<x.length;i++){
i=0;i<x.length;i++){
rs[i]=x[i];
for(int i=0;i<y.length;i++){
i=0;i<y.length;i++){
rs[x.length+i]=y[i];
return rs;
int[]readArr(){
System.out.println("Enter
System.out.println("Enter the size of array");
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter Elements of Array ");
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
ar[i]=sc.nextInt();
return ar;
for(int i=0;i<ele.length;i++){
i=0;i<ele.length;i++){
System.out.print(ele[i]);
if(i<ele.length-1){
System.out.print(",");
System.out.println();
}
public static void main(String[] args) {
int a[]=ma.readArr();
System.out.print("Entered
System.out.print("Entered elements are :");
ma.dispArr(a);
int b[]=ma.readArr();
System.out.print("Entered
System.out.print("Entered elements are :");
ma.dispArr(b);
System.out.println("Merged
System.out.println("Merged values are :");
ma.dispArr(c);
o/p:-
124
Entered elements are :1,2,4
45
1,2,4,4,5,6
package onedimensionarry;
import java.util.Scanner;
for(int i=0;i<x.length;i++){
i=0;i<x.length;i++){
rs[i]=x[i];
}
for(int i=0;i<y.length;i++){
i=0;i<y.length;i++){
rs[x.length+i]=y[i];
return rs;
int[]readArr(){
System.out.println("Enter
System.out.println("Enter the size of array");
int n=sc.nextInt();
System.out.println("enter
System.out.println("enter Elements of Array ");
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
ar[i]=sc.nextInt();
return ar;
System.out.print(ele[i]);
if(i<ele.length-1){
System.out.print(",");
System.out.println();
int a[]=ma.readArr();
System.out.print("Entered
System.out.print("Entered elements are :");
ma.dispArr(a);
int b[]=ma.readArr();
System.out.print("Entered
System.out.print("Entered elements are :");
ma.dispArr(b);
System.out.println("Merged
System.out.println("Merged values are :");
o/p:-
2345
2,3,4,5
123
1,2,3
2,3,4,5,1,2,3
import java.util.Scanner;
int big=a[0];
if( a[i]>big){
return big=a[i];
return big;
System.out.println("Enter
System.out.println("Enter the no
n o of array");
int n=sc.nextInt();
System.out.println("Enter
System.out.println("Enter the elements");
ar[i]=sc.nextInt();
int value=nthBiggest(ar);
System.out.println("biggest "+value);
o/p:-
98 1 77 888 8
biggest 888
2d-array
************
Write a program to reverse elements of matrix
package twodimensional;
import java.util.Scanner;
//rowwise reverse
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
int t=ar[i][j];
ar[i][j]=ar[i][ar[i].length-1-j];
ar[i][ar[i].length-1-j]=t;
System.out.print(ar[i][j]+"
System.out.print(ar[i][j]+" ");
System.out.println();
}
}
//column reverse
for(int i=0;i<arr.length/2;i++){
i=0;i<arr.length/2;i++){
int t=arr[i][j];
arr[i][j]=arr[arr.length-1-i][j];
arr[arr.length-1-i][j]=
arr[arr.length-1-i][j]= t;
System.out.print(arr[i][j]+"
System.out.print(arr[i][j]+" ");
System.out.println();
}
public static void main(String[] args) {
System.out.println("enter
System.out.println("enter the array");
int row=sc.nextInt();
int column=sc.nextInt();
System.out.println("enter
System.out.println("enter the elements");
arr[i][j]=sc.nextInt();
System.out.println("Row
System.out.println("Row Reverse");
rowreverse(arr);
System.out.println("column
System.out.println("column Reverse");
columnreverse(arr);
}
o/p:-enter the array
22 33
44 55
Row Reverse
33 22
55 44
column Reverse
55 44
33 22
package twodimensional;
import java.util.Scanner;
static int[][]readmat(){
int r=sc.nextInt();
int c=sc.nextInt();
//System.out.println("enter"+i+1+"row
//System.out.println("enter"+i+1+"row elements");
mat[i][j]=sc.nextInt();
return mat;
System.out.print(x[i][j]+"
System.out.print(x[i][j]+" ");
}
System.out.println();
if(a.length!=b[0].length
if(a.length!=b[0].length || a[0].length!=b.length){
System.out.println("next elements");
return null;
p[i][j]=a[i][j]+b[i][j];
return p;
}
System.out.println("enter
System.out.println("enter 1st matrix");
int[][] m1=p.readmat();
p.disMat(m1);
System.out.println("enter
System.out.println("enter 2nd matrix");
int[][] m2=p.readmat();
System.out.println("2nd
System.out.println("2nd matrix is : ");
p.disMat(m2);
System.out.println("Sum
System.out.println("Sum of matrix is :");
p.disMat(res);
22
24
35
1st matrix is
24
35
22
36
75
2nd matrix is :
36
75
Sum of matrix is :
5 10
10 10
package twodimensional;
import java.util.Scanner;
static int[][]readmat(){
int r=sc.nextInt();
int c=sc.nextInt();
//System.out.println("enter"+i+1+"row
//System.out.println("enter"+i+1+"row elements");
mat[i][j]=sc.nextInt();
return mat;
System.out.print(x[i][j]+"
System.out.print(x[i][j]+" ");
System.out.println();
if(a.length!=b[0].length
if(a.length!=b[0].length || a[0].length!=b.length){
System.out.println("next elements");
return null;
p[i][j]=p[i][j]+a[i][j]*b[k][j];
}
}
return p;
int[][] m1=p.readmat();
p.disMat(m1);
System.out.println("enter
System.out.println("enter 2nd matrix");
int[][] m2=p.readmat();
p.disMat(m2);
System.out.println("Display
System.out.println("Display multiplication");
multiplication");
p.disMat(res);
}
o/p:-enter 1st matrix
22
34
45
34
45
22
35
67
35
67
Display multiplication
27 48
36 60
package twodimensional;
import java.util.Scanner;
int t=arr[i][j];
arr[i][j]=arr[j][i];
arr[j][i]=t;
System.out.print(arr[i][j]+"
System.out.print(arr[i][j]+" ");
System.out.println();
}
static void columnreverse(int arr[][]){
for(int i=0;i<arr.length/2;i++){
i=0;i<arr.length/2;i++){
int t=arr[i][j];
arr[i][j]=arr[arr.length-1-i][j];
arr[arr.length-1-i][j]=
arr[arr.length-1-i][j]= t;
System.out.print(arr[i][j]+"
System.out.print(arr[i][j]+" ");
System.out.println();
for(int i=0;i<ar.length;i++){
i=0;i<ar.length;i++){
ar[i][j]=ar[i][ar[i].length-1-j];
ar[i][ar[i].length-1-j]=t;
System.out.print(ar[i][j]+"
System.out.print(ar[i][j]+" ");
System.out.println();
transpose(arr);
System.out.println("rotate
System.out.println("rotate 90 left Matrix");
columnreverse(arr);
System.out.println("==========
System.out.println("====================
===========");
=");
transpose(arr);
System.out.println("rotate
System.out.println("rotate 90 right Matrix");
rowreverse(arr);
System.out.println("enter
System.out.println("enter the array");
int row=sc.nextInt();
int column=sc.nextInt();
System.out.println("enter
System.out.println("enter the elements");
arr[i][j]=sc.nextInt();
rotate90left(arr);
rotate90right(arr);
}
o/p:-
22
3 65
79
3 65
79
79
3 65
=====================
79
3 65
97
65 3
Write a program to rotate diagonal of matrix
package twodimensional;
import java.util.Scanner;
if(i==j){
int t=arr[i][j];
arr[i][j]=arr[arr.length-1-i][arr.length-1-j];
arr[arr.length-1-i][arr.length-1-j]=t;
if(i+j==arr.length-1){
int t=arr[i][j];
arr[i][j]=arr[j][i];
arr[i][j]=t;
}
}
System.out.print(arr[i][j]+"
System.out.print(arr[i][j]+" ");
System.out.println();
System.out.println("enter
System.out.println("enter the array");
int row=sc.nextInt();
int column=sc.nextInt();
System.out.println("enter
System.out.println("enter the elements");
arr[i][j]=sc.nextInt();
}
System.out.println("Rotate
System.out.println("Rotate diagonal value");
reverseDigonal(arr);
o/p:-
22
48
89
98
84
import java.util.Scanner;
//int n=5;
System.out.print(ar[i][k]+"
System.out.print(ar[i][k]+" ");
System.out.println();
System.out.print(ar[k][j]+"
System.out.print(ar[k][j]+" ");
System.out.println();
System.out.print(ar[j][k]+"
System.out.print(ar[j][k]+" ");
System.out.println();
for(int k=j;k>i;k--){
System.out.print(ar[k][i]+"
System.out.print(ar[k][i]+" ");
System.out.println();
if(ar.length%2==1)
System.out.print(ar[ar.length/2][ar.length/2]);
System.out.println("enter
System.out.println("enter the array");
int row=sc.nextInt();
int column=sc.nextInt();
System.out.println("enter
System.out.println("enter the elements");
ar[i][j]=sc.nextInt();
}
}
System.out.println("Spiral
System.out.println("Spiral matrix");
s.spiralmat(ar);
o/p:-
22
78
59
Spiral matrix
package twodimensional;
double getArea();
================
Circle class
================
package twodimensional;
double r;
public Circle(double r) {
this.r = r;
}
@Override
return 3.14*r*r;
@Override
=================
Reactangle class
=================
package twodimensional;
double l;
double b;
public Reactangle(double l, double b) {
this.l = l;
this.b = b;
@Override
return 2*l*b;
@Override
Square class
==================
package twodimensional;
double side;
this.side = side;
@Override
return side*side;
@Override
}
mainrunner class
=================
package twodimensional;
//java program to read store shape info and display biggest area shapeinfo.//
import java.util.ArrayList;
java.util.ArrayList;
import java.util.Iterator;
java.util.Iterator;
import java.util.List;
import java.util.Scanner;
while(true){
Shape sh=null;
System.out.println("1.Circle\n2.Square\n3.Reactangle");
int ch=sc.nextInt();
switch(ch){
case 1: System.out.println("Enter
System.out.println("Enter Radius :");
double r=sc.nextDouble();
sh=new Circle(r);
break;
double side=sc.nextDouble();
sh=new Square(side);
break;
double l=sc.nextDouble();
double b=sc.nextDouble();
sh=new Reactangle(l,b);
break;
default:
sh=null;
break;
if(sh!=null)
shapes.add(sh);
if(s.equalsIgnoreCase("no")){
break;
return shapes;
Shape b=ls.get(0);
Iterator<Shape> it=ls.iterator();
while(it.hasNext()){
Shape s=it.next();
if(b.getArea()<s.getArea())
b=s;
return b;
System.out.println(shape);
List<Shape> ls =getShapes();
Shape big=BiggestAreashape
big=BiggestAreashape(ls);
(ls);
System.out.println("Shapes
System.out.println("Shapes info :");
displayshape(ls);
System.out.println("biggest
System.out.println("biggest Area shape is:");
System.out.println(big);
o/p:-
1.Circle
2.Square
3.Reactangle
Enter shape no
Enter Radius :
yes
1.Circle
2.Square
3.Reactangle
Enter shape no
Enter side :
no
Shapes info :
formed from
listen
import java.util.Scanner;
int count1[]=noofOccurence(st1);
count1[]=noofOccurence(st1);
int count2[]=noofOccurence(st2);
count2[]=noofOccurence(st2);
if(count1[i]!=count2[i])
return false;
return true;
}
static int[] noofOccurence(String
noofOccurence(String st){
int[]count=new int[26];
char ch=st.charAt(i);
if(ch>='A'&&ch<='Z'){
count[ch-65]++;
if(ch>='a'&&ch<='z'){
count[ch-97]++;
return count;
System.out.println("Enter
System.out.println("Enter first String");
String st1=sc.nextLine();
st1=sc.nextLine();
System.out.println("Enter
System.out.println("Enter second String");
String st2=sc.nextLine();
st2=sc.nextLine();
boolean bb=an.isanagram(st2, st1);
if(bb)
else
System.out.println("not ");
o/p:-
reverse
serever
============================================================
Write program weather the string is PANAGRAM or
not?
import java.util.Scanner;
int[]count=new int[26];
char ch=st.charAt(i);
if(ch>='A'&&ch<='Z'){
count[ch-65]++;
if(ch>='a'&&ch<='z'){
count[ch-97]++;
for(int i=0;i<count.length;i++){
i=0;i<count.length;i++){
System.out.println((char)(i+65)+"-->
System.out.println((char)(i+65)+"--> "+count[i]);
if(count[i]==0)
return false;
return true;
System.out.println("Enter
System.out.println("Enter the sentence.");
String s=sc.nextLine();
System.out.println(ispanagram(s));
import java.util.Scanner;
while(i<st.length()/2){
if(st.charAt(i)!=st.charAt(st.length()-1-i))
return false;
i++;
return true;
System.out.println("Enter
System.out.println("Enter the sentence.");
String s=sc.nextLine();
boolean str=ispalindrom(s);
if(str)
System.out.println(s+" is palindrom");
else
}
o.p:-
qwerty ytrewq
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the sentence.");
String s=sc.nextLine();
System.out.println("Aftr conversion");
String str=reverseSentence(s);
str=reverseSentence(s);
System.out.println(str);
}
char ch[]=st.toCharArray();
st=" ";
int k=i;
while(i>=0&&ch[i]!='
while(i>=0&&ch[i]!=' '){
i--;
int j=i+1;
while(j<=k){
st=st+ch[j];
j++;
if(i>0)
st=st+ch[i];
return st;
}
o/p:
qwerty id
Aftr conversion
id qwerty
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the sentence.");
String s=sc.nextLine();
System.out.println("Aftr conversion");
String str=reversewordSentence(s);
str=reversewordSentence(s);
System.out.println(str);
st=" ";
int k=i;
while(i<ch.length&&ch[i]!='
while(i<ch.length&&ch[i]!=' '){
i++;
int j=i-1;
while(j>=k){
st=st+ch[j];
j--;
if(i<ch.length)
st=st+ch[i];
return st;
o/p:-
qwertty
Aftr conversion
yttrewq
import java.util.Scanner;
int count=0;
char ch[]=st.toCharArray();
if(ch[i]>=65&&ch[i]<=90
if(ch[i]>=65&&ch[i]<=90 ||ch[i]>=97 &&
ch[i]<=122||ch[i]>=48&&ch[i]
ch[i]<=122||ch[i]>=48&&ch[i]<=57
<=57 && ch[i]!=32 && ch[i]!=',' &&ch[i]!='.')
count++;
return count;
String st=sc.nextLine();
int chr=countchar(st);
System.out.println("total
System.out.println("total no charcters = "+chr);
o/p:-
qwerty
total no charcters = 6
import java.util.Scanner;
int wc=0;
char ch[]=st.toCharArray();
for (int i = 0; i < ch.length; i++) {
wc++;
return wc;
System.out.println("Enter
System.out.println("Enter the word");
String st=sc.nextLine();
int chr=countWords(st);
System.out.println("total
System.out.println("total no word = "+chr);
QWERTY ID IS NON
total no word = 4
Write a program to find the sum of numbers in an
ALPHA NUMERIC STRING?
import java.util.Scanner;
int sum=0;
char ch=st.charAt(i);
if(ch>=48 &&ch<=57){
sum=sum+(ch-48);
return sum;
System.out.println("Enter
System.out.println("Enter the word");
String st=sc.nextLine();
int sm=sumOfDigit(st);
sm=sumOfDigit(st);
System.out.println("Total
System.out.println("Total sum is "+sm);
O/P:-
Q1W2E3R45T
Total sum is 15
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the Sentence");
String st=scn.nextLine();
//ac=alphabets;
//vc=vowels;
//cc=consonents
//dc=degits
//uc=upper case
//lc=lower case
//sc=special character
int ac=0,vc=0,cc=0,dc=0,uc=0,l
ac=0,vc=0,cc=0,dc=0,uc=0,lc=0,sc=0;
c=0,sc=0;
for(int i=0;i<st.length();i++){
i=0;i<st.length();i++){
char ch=st.charAt(i);
if(ch>=65&&ch<=90){
ac++;
uc++;
if(ch=='A'||ch=='E'||ch=='I'||c
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
h=='O'||ch=='U')
vc++;
else
cc++;
else if(ch>='a'&&ch<='z'){
if(ch>='a'&&ch<='z'){
ac++;
lc++;
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
vc++;
else
cc++;
else if(ch>=48&&ch<=57)
if(ch>=48&&ch<=57)
dc++;
else
sc++;
System.out.println("Total
System.out.println("Total upper case="+uc);
System.out.println("total
System.out.println("total lower case="+lc);
System.out.println("total
System.out.println("total vowels ="+vc);
System.out.println("total
System.out.println("total consonents"+cc);
consonents"+cc);
System.out.println("total
System.out.println("total special characters = "+sc);
}
O/P:-
QWERTT Y KM
no of alphabets = 9
no of degits = 0
total vowels = 1
total consonents = 8
import java.util.Scanner;
import twodimensional.MainRunner;
twodimensional.MainRunner;
String one[]={"
","one","two","three","four",
","one","two","three","four","five","Six","
"five","Six","Seven","Eight","
Seven","Eight","Nine","Ten","Eleven"
Nine","Ten","Eleven","T
,"T
welve","thirteen","fourteen","f
welve","thirteen","fourteen","fifteen","Sixt
ifteen","Sixteen","Seventeen
een","Seventeen","Eightteen","
","Eightteen","Ninete
Ninete
en"};
if(n<20)
System.out.print(one[n]);
else
System.out.print(two[n/10]+one[n%10]);
if(n!=0)
System.out.print(st+" ");
System.out.println("Enter
System.out.println("Enter the no");
int n=sc.nextInt();
nw.ntow(n/10000000,"crore");
nw.ntow(n/100000%100,"lakh");
nw.ntow(n/1000%100,"Thousand");
nw.ntow(n/100%10,"hundred");
nw.ntow(n%100," ");
O/P:-
Enter the no
145
onehundred foutyfive
import java.util.Scanner;
char ch[]=st.toCharArray();
if(ch[i]>='a'&&ch[i]<='z'){
ch[i]=(char)(ch[i]-32);
else{
if(ch[i]>='A'&&ch[i]<='Z'){
ch[i]=(char)(ch[i]+32);
st=new String(ch);
return st;
System.out.println("Enter
System.out.println("Enter the sentence.");
String s=sc.nextLine();
System.out.println("Aftr conversion");
String str=initcap(s);
System.out.println(str);
O/P:-
RANMDND
Aftr conversion
Ranmdnd
import java.util.Scanner;
public class ConvertLowercase {
char ch[]=str.toCharArray();
if(ch[i]>=65&&ch[i]<=90){
ch[i]=(char) (ch[i]+32);
return st;
String ls="";
if(ch>=65&&ch<=90){
ch=(char) (ch+32);
ls=ls+ch;
return ls;
System.out.println("Enter
System.out.println("Enter the Word");
String sd=sc.nextLine();
String s=lc.tolowercase(sd) ;
System.out.println("Enter
System.out.println("Enter the Word");
String sd1=sc.nextLine();
sd1=sc.nextLine();
String st=lc.toLowerCase(sd1) ;
System.out.println(s);
System.out.println(st);
}
}
O/P:-
QWERT
REWQ
qwert
rewq
import java.util.Scanner;
String ls="";
char ch=str.charAt(i);
if(ch>=97&&ch<=122){
ch=(char) (ch-32);
ls=ls+ch;
return ls;
System.out.println("Enter
System.out.println("Enter the word");
String st=sc.nextLine();
String s=uc.touppercase(st) ;
O/P:-
qwerty
the uppercase of qwerty is QWERTY
import java.util.Scanner;
System.out.println("Enter
System.out.println("Enter the sentence ");
String st=sc.nextLine();
System.out.println("Enter
System.out.println("Enter the word to search: ");
String w=sc.next();
if(rs)
System.out.println("yes
System.out.println("yes word is there ");
else
}
private static boolean subStr(String st, String w)
char c1[]=st.toCharArray();
c1[]=st.toCharArray();
char c2[]=w.toCharArray();
for(int i=0;i<c1.length;i++)
i=0;i<c1.length;i++)
int j=0;
int k=i;
while(k<c1.length&&j<c2.length&&c1[k]==c2[j])
k++;
j++;
if(j==c2.length)
return true;
return false;
{
char c1[]=st.toCharArray();
c1[]=st.toCharArray();
char c2[]=w.toCharArray();
int count=0;
for(int i=0;i<c1.length;i++)
i=0;i<c1.length;i++)
int j=0;
int k=i;
while(k<c1.length&&j<c2.length&&c1[k]==c2[j])
k++;
j++;
if(j==c2.length)
count++;
return count;
char c1[]=st.toCharArray();
c1[]=st.toCharArray();
char c2[]=w.toCharArray();
int count=0;
for(int i=0;i<c1.length;i++)
i=0;i<c1.length;i++)
int j=0;
int k=i;
while(k<c1.length&&j<c2.length&&c1[k]==c2[j])
k++;
j++;
if(j==c2.length)
return i;
return -1;
char c1[]=st.toCharArray();
c1[]=st.toCharArray();
char c2[]=w.toCharArray();
int count=0;
for(int i=0;i<c1.length;i++)
i=0;i<c1.length;i++)
{
int j=0;
int k=i;
while(k<c1.length&&j<c2.length&&c1[k]==c2[j])
k++;
j++;
if(j==c2.length)
count++;
if(count==oc)
return i;
return -1;
}
private static boolean checkWord(String st, String w)
char c1[]=st.toCharArray();
c1[]=st.toCharArray();
char c2[]=w.toCharArray();
for(int i=0;i<c1.length;i++)
i=0;i<c1.length;i++)
int j=0;
int k=i;
while(k<c1.length&&j<c2.length&&c1[k]==c2[j])
k++;
j++;
if(j==c2.length&&(i==0||c1[i-1]=
if(j==c2.length&&(i==0||c1[i-1]=='
=' ')&&(k==c1.length||c1[k]=='
')&&(k==c1.length||c1[k]==' '))
return true;
return false;
}
o/p:-
qwerty u tyu
tyu
import java.nio.charset.MalformedInputException
java.nio.charset.MalformedInputException;;
import java.util.Scanner;
int dd,mm,yy;
int month[]={0,31,28,31,30,3
month[]={0,31,28,31,30,31,30,31,31
1,30,31,31,30,31,30,3
,30,31,30,31};
1};
this.dd = dd;
this.mm = mm;
this.yy = yy;
if(yy%4==0&&yy%100!=0||yy%400==0)
month[2]=29;
int countnodays(){
int y=yy-1;
int days=0;
days=y*365;
days=days+(y/4-y/100+y/400);
for(int i=1;i<mm;i++){
i=1;i<mm;i++){
days=days+month[i];
days=days+dd;
return days;
System.out.println("Enter
System.out.println("Enter dd mm yyyy");
int dd=sc.nextInt();
int mm=sc.nextInt();
int yy=sc.nextInt();
Date d=new Date(dd,mm,yy);
return d;
@Override
System.out.println("enter
System.out.println("enter first date :");
Date d1=Date.readdate();
d1=Date.readdate();
System.out.println("Enter
System.out.println("Enter 2nd date :");
Date d2=Date.readdate();
d2=Date.readdate();
int days=d2.countnodays()-d1.countn
days=d2.countnodays()-d1.countnodays();
odays();
System.out.println("total
System.out.println("total year,months till dates "+days/365+"
"+days/365+"
"+days%365/30);
output
Enter dd mm yyyy
03 02 1997
Enter dd mm yyyy
02 03 1998
total year,months
year,months till dates 1 0