import java.util.
*;
class Strontio
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a 4 digit no.");
int n= sn.nextInt();
if (n<1000 || n>9999)
System.out.println ("Invalid input");
System.exit(0);
n= n*2;
int no= n;
int t=0;
int h=0;
for (int i=1; i<=2; i++)
int d= no%10;
no= no/10;
t=d;
int d= no%10;
h= d;
if (t==h)
System.out.println ("It is a strontio no");
else
System.out.println ("It is not a strontio no");
}
import java.util.*;
class Evil
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a number");
int n= sn.nextInt();
if (n<0)
System.out.println ("Invalid input");
System.exit(0);
int no= n;
String s="";
while (no!=0)
int d= no%2;
no= no/2;
s= d+s;
int c=0;
for (int i=0; i<s.length(); i++)
char x= s.charAt(i);
if (x=='1')
c++;
System.out.println ("Binary equivalent: "+s);
System.out.println ("Number of 1's: "+c);
if (c%2==0)
System.out.println ("Evil number");
else
System.out.println ("Not an evil number");
import java.util.*;
class Sum
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter m");
int m= sn.nextInt();
if (m>10000)
System.out.println ("Invalid input");
System.exit(0);
else
System.out.println ("Enter n");
int n= sn.nextInt();
int s= 0;
int c=0;
int f=0;
for (int i=m; i<=10000; i++)
int j=i;
c=0;
s=0;
while (j!=0)
int d= j%10;
j= j/10;
s= s+d;
c++;
if (s==n)
System.out.println ("The required no. of digits= "+c);
System.out.println ("The no= "+i);
f++;
System.out.println ("Frequency= "+f);
if (f==0)
System.out.println ("No. not found");
import java.util.*;
class Ore
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a number");
int n= sn.nextInt();
if (n<0)
System.out.println ("Invalid input");
System.exit(0);
else
int s=0;
int c=0;
int i=0;
for (i=1; i<=n; i++)
if (n%i==0)
s= s+i;
c++;
double g= c*n;
double h= g/ s;
double k= h- (int)h;
if (k==0.0)
System.out.println ("It is an ore no.");
else
System.out.println ("It is not an ore no.");
}
import java.util.*;
class Goldbach
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter an even no. between 9 and 50");
int N= sn.nextInt();
int s1=0;
int s2=0;
int c=0;
if (N%2==1)
System.out.println ("Invalid input, number is odd");
System.exit(0);
else if (N<9 || N>50)
System.out.println ("Invalid input, number out of range");
System.exit(0);
else
System.out.println ("Prime pairs are: ");
for (int i=3; i<=N/2; i+=2)
c=0;
for (int j=1; j<=i; j++)
if (i%j==0)
c++;
}
if (c==2)
s1= i;
s2= N-s1;
c=0;
for (int k=1; k<=s2; k++)
if (s2%k==0)
c++;
if (c==2)
System.out.print (s1+ ", "+ s2);
System.out.println ();
import java.util.*;
class Composite_Magic
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter m");
int m= sn.nextInt();
System.out.println ("Enter n");
int n= sn.nextInt();
int c=0; int l=0;
if (m>n || m<0 || n<0)
System.out.println ("Invalid input");
System.exit(0);
else
System.out.print ("The composite magic numbers are ");
for (int i=m; i<=n; i++)
c=0;
for (int j=1; j<=i; j++)
if (i%j==0)
c++;
if (c>2)
int k=i;
int s=0;
while (k>9)
s=0;
while (k!=0)
int d= k%10;
k= k/10;
s+=d;
}
k=s;
if (k==1)
System.out.print (i +", ");
l++;
System.out.println ();
System.out.println ("Frequency of composite magic numbers: "+l);
import java.util.*;
class ISBN
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a 10-digit no.");
long n= sn.nextInt();
String s= Long.toString(n);
int l= s.length();
if (l!=10)
System.out.println ("Illegal ISBN");
System.exit(0);
}
else
int i=1;
long no=n;
int sum=0;
while (no!=0)
int d= (int) no%10;
no= no/10;
sum= sum+ (d*i);
i++;
if (sum%11==0)
System.out.println ("Legal ISBN");
else
System.out.println ("Illegal ISBN");
import java.util.*;
class Matrix_20
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.print ("Enter the no. of rows (M): ");
int M= sn.nextInt();
System.out.print ("Enter the no. of columns (N): ");
int N= sn.nextInt();
String s= "";
if (M<=0 || M>=10 || N<=2 || N>=6)
System.out.println ("INVALID INPUT");
System.exit(0);
else
int i=0;
int j=0;
int A[][]= new int [M][N];
for (i=0; i<M; i++)
System.out.println ("ENTER ELEMENTS FOR ROW "+(i+1)+": ");
for (j=0; j<N; j++)
A[i][j]= sn.nextInt();
if (A[i][j]>=8 || A[i][j]<0)
System.out.println ("Invalid input");
System.exit(0);
System.out.println ("FILLED MATRIX \t \t \t DECIMAL EQUIVALENT");
for (i=0; i<M; i++)
for (j=0; j<N; j++)
System.out.print (A[i][j]+ "\t");
s= s+A[i][j];
int o= Integer.parseInt(s);
int no=o;
int x= 0;
int sum=0;
while (no!=0)
int d= no%10;
no= no/10;
sum= sum+ (int)(d*(Math.pow (8, x)));
x++;
System.out.println (sum);
sum=0;
x=0;
s= "";
System.out.println ();
import java.util.*;
class Array_19
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.print ("ENTER VALUE OF N: ");
int N= sn.nextInt();
int a[]= new int [N];
int b[][]= new int [N][N];
if (N<2 || N>10)
System.out.println ("MATRIX SIZE OUT OF RANGE");
System.exit(0);
System.out.println ("ENTER ELEMENTS OF SINGLE DIMENSIONAL ARRAY: ");
int i=0;
int j=0;
for (i=0; i<N; i++)
a[i]= sn.nextInt();
System.out.println ("SORTED ARRAY: ");
for (i=0; i<N-1; i++)
for (j=0; j<N-1-i; j++)
if (a[j]>a[j+1])
int t= a[j];
a[j]= a[j+1];
a[j+1]= t;
for (i=0; i<N; i++)
System.out.print (a[i]+ "\t");
}
System.out.println ();
System.out.println ("FILLED MATRIX:");
int x= N;
int r=0;
for (i=N-1, r=0; i>=0; i--, r++)
for (j=0; j<=i; j++)
b[r][j]=a[j];
for (int k= N-1; k>i; k--)
b[r][k]=a[k-i-1];
for (i=0; i<N; i++)
for (j=0; j<N; j++)
System.out.print (b[i][j]+ "\t");
System.out.println ();
import java.util.*;
class Matrix_18
public static void main ()
{
Scanner sn= new Scanner (System.in);
System.out.print ("ENTER THE VALUE OF M: ");
int M= sn.nextInt();
System.out.print ("ENTER THE VALUE OF N: ");
int N= sn.nextInt();
int a[][]= new int [M][N];
if (M<=2 || M>=10 || N<=2 || N>=10)
System.out.println ("MATRIX SIZE OUT OF RANGE.");
System.exit(0);
else
System.out.println ("ENTER ELEMENTS OF MATRIX:");
int i=0;
int j=0;
for (i=0; i<M; i++)
System.out.println ("ENTER ELEMENTS OF ROW "+(i+1)+": ");
for (j=0; j<N; j++)
a[i][j]=sn.nextInt();
System.out.println ("ORIGINAL MATRIX");
for (i=0; i<M; i++)
for (j=0; j<N; j++)
System.out.print (a[i][j]+ "\t");
}
System.out.println ();
System.out.println ("MATRIX AFTER SORTING ROWS");
for (i=0; i<M; i++)
int x=0;
int b[]= new int [N];
for (j=0; j<N; j++)
b[x++]= a[i][j];
for (int k=0; k<N-1; k++)
for (int l=0; l<N-k-1; l++)
if (b[l]>b[l+1])
int t= b[l];
b[l]= b[l+1];
b[l+1]= t;
for (int h=0; h<N; h++)
System.out.print (b[h]+ "\t");
System.out.println();
}
}
import java.util.*;
class Matrix_16
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.print ("ENTER MATRIX SIZE (M): ");
int M= sn.nextInt();
int A[][]= new int [M][M];
if (M<3 || M>10)
System.out.print ("THE MATRIX SIZE IS OUT OF RANGE.");
System.exit(0);
else
System.out.println ("Enter the elements");
int i=0;
int j=0;
for (i=0; i<M; i++)
for (j=0; j<M; j++)
A[i][j]= sn.nextInt();
System.out.println ("ORIGINAL MATRIX");
for (i=0; i<M; i++)
for (j=0; j<M; j++)
System.out.print (A[i][j]+ "\t");
System.out.println ();
System.out.println ("REARRANGED MATRIX");
int B[]= new int [(M-2)*(M-2)];
int k=0;
for (i=1; i<M-1; i++)
for (j=1; j<M-1; j++)
B[k++]=A[i][j];
for (i=0; i<k-1; i++)
for (j=0; j<k-i-1; j++)
if (B[j]>B[j+1])
int t= B[j];
B[j]= B[j+1];
B[j+1]= t;
k=0;
for (i=1; i<M-1; i++)
for (j=1; j<M-1; j++)
A[i][j]= B[k++];
for (i=0; i<M; i++)
for (j=0; j<M; j++)
System.out.print (A[i][j]+"\t");
System.out.println ();
System.out.println ("DIAGONAL ELEMENTS");
int sum=0;
for (i=0; i<M; i++)
for (j=0; j<M; j++)
if (i==j || i+j==M-1)
System.out.print (A[i][j]+ "\t");
sum+=A[i][j];
else
System.out.print ("\t");
System.out.println ();
}
System.out.println ("SUM OF THE DIAGONAL ELEMENTS = "+sum);
import java.util.*;
class Potential
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("ENTER THE SENTENCE:");
String s= sn.nextLine();
int i=0;
int j=0;
int m=0;
int n=0;
int l=0;
int sum=0;
char k= s.charAt(s.length()-1);
if (k!='.' || k!=',' || k!='?' || k!='!')
System.out.println ("INVALID INPUT");
System.exit(0);
System.out.println ("Potential:");
StringTokenizer st= new StringTokenizer (s, " , ., ,, ?, !");
l= st.countTokens();
int A[]= new int [l];
String stri[]= new String [l];
while (st.hasMoreTokens())
String str= st.nextToken();
for (i=0; i<str.length(); i++)
char x= str.charAt(i);
sum+= (x-64);
A[m++]= sum;
stri[n++]= str;
System.out.println (str+ " = "+sum);
sum=0;
System.out.println ("Sorted sentence");
for (i=0; i<l-1; i++)
for (j=0; j<l-i-1; j++)
if (A[j]>A[j+1])
int t= A[j];
A[j]= A[j+1];
A[j+1]= t;
String strin= stri[j];
stri[j]= stri[j+1];
stri[j+1]= strin;
for (i=0; i<l; i++)
{
System.out.print (stri[i]+ " ");
import java.util.*;
class CW
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter the size of the array");
int m= sn.nextInt();
System.out.println ("Enter the elements");
int A[][]= new int [m][m];
int i=0;
int j=0;
for (i=0; i<m; i++)
for (j=0; j<m; j++)
A[i][j]= sn.nextInt();
int B[][]= new int [m][m];
for (i=0; i<m; i++)
for (j=0; j<m; j++)
B[i][j]= A[j][i];
}
for (i=0; i<m; i++)
for (j=m-1; j>=0; j--)
System.out.print (B[i][j]+ "\t");
System.out.println ();
import java.util.*;
class ACW
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter the size of the array");
int m= sn.nextInt();
System.out.println ("Enter the elements");
int A[][]= new int [m][m];
int i=0;
int j=0;
for (i=0; i<m; i++)
for (j=0; j<m; j++)
A[i][j]= sn.nextInt();
}
int B[][]= new int [m][m];
for (i=0; i<m; i++)
for (j=0; j<m; j++)
B[i][j]= A[j][i];
for (i=m-1; i>=0; i--)
for (j=0; j<m; j++)
System.out.print (B[i][j]+ "\t");
System.out.println ();
import java.util.*;
class Mirror
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter the no. of rows");
int m= sn.nextInt();
System.out.println ("Enter the no. of columns");
int n= sn.nextInt();
System.out.println ("Enter the elements");
int A[][]= new int [m][n];
int i=0;
int j=0;
for (i=0; i<m; i++)
for (j=0; j<m; j++)
A[i][j]= sn.nextInt();
System.out.println ("INPUT ARRAY: ");
for (i=0; i<m; i++)
for (j=0; j<m; j++)
System.out.print (A[i][j]+ "\t");
System.out.println ();
System.out.println ("MIRROR IMAGE ARRAY: ");
for (i=0; i<m; i++)
for (j=m-1; j>=0; j--)
System.out.print (A[i][j]+ "\t");
System.out.println ();
}
}
import java.util.*;
class Doubly_Markov
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter the no. of rows");
int m= sn.nextInt();
System.out.println ("Enter the no. of columns");
int n= sn.nextInt();
System.out.println ("Enter the elements");
int A[][]= new int [m][n];
int i=0;
int j=0;
for (i=0; i<m; i++)
for (j=0; j<m; j++)
A[i][j]=sn.nextInt();
int sum=0;
int c=0;
for (i=0; i<m; i++)
for (j=0; j<m; j++)
sum+= A[i][j];
}
if (sum==1)
c++;
sum=0;
if (c==m)
System.out.println ("It is a doubly markov matrix");
else
System.out.println ("It is not a doubly markov matrix");
import java.util.*;
class Xylem_Phloem
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a no.");
int n= sn.nextInt();
String s= Integer.toString(n);
int l= s.length();
int i=0;
String s1="";
int n1=0;
int n2=0;
char x;
char x1;
char x2;
int sum1=0;
int sum2=0;
for (i=1; i<l-1; i++)
x= s.charAt(i);
s1+= x;
n1= Integer.parseInt(s1);
int no= n1;
while (no!=0)
int d= no%10;
no= no/10;
sum1+= d;
x1= s.charAt(0);
x2= s.charAt(l-1);
sum2= (int) x1+ (int) x2;
sum2-= (48*2);
if (sum1==sum2)
System.out.println ("It is a xylem no");
else
System.out.println ("It is a phloem no");
import java.util.*;
class Bouncy
public static void main ()
{
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a no.");
int n= sn.nextInt();
int no= n;
int n1=0;
int n2=0;
String s= Integer.toString(n);
String s1= "";
String s2= "";
int l= s.length();
n= Integer.parseInt(s);
if (n<100)
System.out.println ("It is not a bouncy no.");
System.exit(0);
int A[]= new int [l];
int i=0;
int j=0;
while (no!=0)
int d= no%10;
no= no/10;
A[i++]=d;
for (i=0; i<l-1; i++)
for (j=0; j<l-i-1; j++)
if (A[j]>A[j+1])
{
int t= A[j];
A[j]= A[j+1];
A[j+1]= t;
for (i=0; i<l; i++)
s1+=A[i];
for (i=l-1; i>=0; i--)
s2+=A[i];
n1= Integer.parseInt(s1);
n2= Integer.parseInt(s2);
if (n1==n || n2==n)
System.out.println ("It is not a bouncy no.");
else
System.out.println ("It is a bouncy no.");
import java.util.*;
class Smith
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a no.");
int n= sn.nextInt();
int i=0;
int c=0;
for (i=1; i<=n; i++)
if (n%i==0)
c++;
if (c<=2)
System.out.println ("Invalid input");
System.exit(0);
c=0;
int no= n;
int s=0;
while (no!=0)
int d= no%10;
no= no/10;
s+=d;
int sum=0;
no= n;
for (i=2; i<=no; i++)
while (no%i==0)
no/= i;
int t=i;
while (t!=0)
{
int d= t%10;
t= t/10;
sum+=d;
if (s==sum)
System.out.println ("It is a smith no.");
else
System.out.println ("It is not a smith no.");
import java.util.*;
class Odins
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter a number");
int n= sn.nextInt();
if (n<0)
System.out.println ("Invalid input");
System.exit(0);
int no= n;
String s="";
while (no!=0)
{
int d= no%2;
no= no/2;
s= d+s;
int c=0;
for (int i=0; i<s.length(); i++)
char x= s.charAt(i);
if (x=='1')
c++;
System.out.println ("Binary equivalent: "+s);
System.out.println ("Number of 1's: "+c);
if (c%2==1)
System.out.println ("Odins number");
else
System.out.println ("Not an odins number");
import java.util.*;
class Array_Arrange
public static void main ()
Scanner sn= new Scanner (System.in);
System.out.println ("Enter the size of the array");
int n= sn.nextInt();
if (n<2 || n>10)
{
System.out.println ("Invalid input");
System.exit(0);
int A[]= new int [n];
System.out.println ("Enter the elements");
int i=0;
for (i=0; i<n; i++)
A[i]= sn.nextInt();
for (i=0; i<n-1; i++)
for (int j=0; j<n-i-1; j++)
if (A[j]>A[j+1])
int t= A[j];
A[j]= A[j+1];
A[j+1]= t;
int l=0;
int B[];
int C[];
int c=0;
if (n%2==0)
l= (n/2);
B= new int [l];
C= new int [l];
B[l-1]= A[0];
c=2;
for (i=l-2; i>=0; i--)
B[i]= A[c];
c+=2;
c=1;
for (i=0; i<l; i++)
C[i]= A[c];
c+=2;
c=0;
for (i=0; i<l; i++)
A[i]= B[c++];
c=0;
for (i=l; i<n; i++)
A[i]= C[c++];
else
l= (n/2)+1;
B= new int [l];
C= new int [l-1];
B[l-1]= A[0];
c=2;
for (i=l-2; i>=0; i--)
B[i]= A[c];
c+=2;
c=1;
for (i=0; i<l-1; i++)
C[i]= A[c];
c+=2;
c=0;
for (i=0; i<l; i++)
A[i]= B[c++];
c=0;
for (i=l; i<n; i++)
A[i]= C[c++];
for (i=0; i<n; i++)
System.out.print (A[i]+ "\t");