2000.Q.No.1 Happy-Happy Refer Your Record //Q2.2000. To Print The Elapsed Days Between 2 Dates
2000.Q.No.1 Happy-Happy Refer Your Record //Q2.2000. To Print The Elapsed Days Between 2 Dates
2000.Q.No.1 Happy-Happy Refer Your Record //Q2.2000. To Print The Elapsed Days Between 2 Dates
System.out.print(d+"= "+cd+")");
}//main
}//end
//2001 Q.no.3 A[] of N integers B[] of M integers merge them in array C[] using sorting while
//merging Refer your record
// 2002 Q.no.1 To read N and print out the twin prime pair that has
//smallest distance from N
import java.io.*;
public class Q1_2002
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int N,i;
int prime1[],prime2[],prime3[];
prime1=new int[2];
prime2=new int[2];
prime3=new int[2];
System.out.print("Input:\n");
System.out.print("Give the number:");
N=Integer.parseInt(b.readLine());
System.out.print("Output:\n");
System.out.print("Number read in is:"+N);
//loop to find out the first twin prime pair <=N
for(i=N;;i--)
{
int f=prime(i);
if(f==1)
{
int m=prime(i-2);
if(m==1)
{
prime1[0]=i;
prime1[1]=i-2;
break;
}
}
}//loop end
//loop to find out the first twin prime pair >=N
for(i=N;;i++)
{
int f=prime(i);
if(f==1)
{
int m=prime(i+2);
if(m==1)
{
prime2[0]=i;
prime2[1]=i+2;
break;
}
}
}//loop end
//statements to find out N+1 and N-1 is the twin prime pair
int m=prime(N+1);
int n=prime(N-1);
if(m==1&&n==1)
{
prime3[0]=N-1;
prime3[1]=N+1;
}
int dis1=Math.abs(N-prime1[0]);
int dis2=Math.abs(N-prime2[0]);
int dis3=Math.abs(N-prime3[0]);
//to print the desired output
if(dis1<dis2&&dis1<dis3)
System.out.print("\np1="+prime1[0]+"\tp2="+prime1[1]);
else if(dis2<dis3)
System.out.print("\np1="+prime2[0]+"\tp2="+prime2[1]);
else
System.out.print("\np1="+prime3[0]+"\tp2="+prime3[1]);
}//main
//Function to check x is prime or not
public static int prime(int x)
{ int c=0;
for(int i=1;i<=x;i++)
{ if(x%i==0)c++;}
if(c==2) return 1;
else return 0;
}
}//class
//2002 Q.no.2 To rearrange the integers in given array DATA
import java.io.*;
class Q2_2002
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int data[],n,c=1,sec,fir,j=0;
int lar,pos=0,i,k;
data=new int[50];
System.out.print("Input:\n");
System.out.print("Give the number of integers:");
n=Integer.parseInt(b.readLine());
//loop to enter the integers and store the in data[]
for(i=0;i<n;i++)
{
System.out.print("Give integer "+(i+1)+":");
data[i]=Integer.parseInt(b.readLine());
}
System.out.print("Output:\n");
System.out.print("Original array\n");
//loop to print the original array
for(i=0;i<n;i++)
System.out.print(data[i]+"\t");
System.out.print("\nRearranged array\n");
if(n%2==0) {fir=n/2-2;sec=n/2;j=1;}
else
{fir=n/2-1;sec=n/2+1;}
lar=data[0];
//loop to find the largest number and its index
for(i=1;i<n;i++)
{ if(data[i]>lar)
{lar=data[i];
pos=i;
}
}
//statements to swap the largest number with the middle element of data[]
int t=data[n/2-j];
data[n/2-j]=lar;
data[pos]=t;
//loop to rearrange the numbers as given
while(fir>=0&&sec<n)
{ lar=data[0];pos=0;
//loop to find largest no and index in the first half of data[]
for(k=1;k<=fir;k++)
{
if(data[k]>lar)
{
lar=data[k];pos=k;
}
}
//loop to find largest no and index in the second half of data[]
for(k=sec;k<n;k++)
{
if(data[k]>lar)
{
lar=data[k];
pos=k;
}
}
//statements to exchange the elements
if(c%2==1)
{
t=data[sec];
data[sec]=lar;
data[pos]=t;
sec++;c++;
}
else
{
t=data[fir];
data[fir]=lar;
data[pos]=t;
fir--;c++;
}
}//end of while
//loop to print the rearranged array
for(i=0;i<n;i++)
System.out.print(data[i]+"\t");
}//main
}//class
//2002 Q.NO.3 LINKED LIST
/*2003 Q.no.1 To input a coded text and decodes it
SAMPLE DATA:
INPUT:
CODED TEXT: UHINBYLKKQCHHYLKK
SHIFT : 7
OUTPUT:
DECODED TEXT: ANOTHER WINNER*/
import java.io.*;
class Q1_2003
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
String s="";
System.out.print("SAMPLE DATA:\n");
System.out.print("INPUT:\n");
System.out.print("CODED TEXT: ");
s=b.readLine();
int sv,i;
System.out.print("SHIFT : ");
sv=Integer.parseInt(b.readLine());
System.out.print("OUTPUT:\n");
if(sv>26)
System.out.print("INVALID SHIFT VALUE.");
else
{
System.out.print("DECODED TEXT: ");
int l=s.length();
sv=sv-1;
//Loop to obtain the desired output
for(i=0;i<l;i++)
{
int nv=s.charAt(i)+sv;//Statement to get the ASCII value of s[i] after //adding the shift value
char c=(char)nv;
if(c=='Q')System.out.print(" ");//Statement to print the blank space
else
{
if(nv<=90)
System.out.print(c);
else
{
//Statements to print the equivalent alphabets when the ASCII value beyond 90
nv=nv-90;
System.out.print((char)(nv+64));
}
}
}//i loop
}//else
}//main
}//class
//2003 Q.No.2 To convert time in numbers into words
import java.io.*;
class Q2_2003
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
String h[]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"};
String m[]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen",
"seventeen","eighteen","nineteen","twenty"};
int hrs,sec;char com;
System.out.print("INPUT:\nTIME:");
hrs=Integer.parseInt(b.readLine());
sec=Integer.parseInt(b.readLine());
//TO VALIDATE THE INPUT
if(sec>=60||sec<0||hrs<1||hrs>12)
{
System.out.print("OUTPUT: INCORRECT INPUT\n");System.exit(0);
}
if(sec==0)
System.out.print(h[hrs-1]+" o' clock");
else if(sec<=30)//to print the message "past"
{
if(sec==15)
System.out.print("quarter past "+h[hrs-1]);
else if(sec==30)
System.out.print("half past "+h[hrs-1]);
else
{
if(sec<=20)
{ if(sec==10)
System.out.print("ten minutes past "+h[hrs-1]);
else if(sec==20)
System.out.print("twenty minutes past "+h[hrs-1]);
else
{ if(sec<10)
{System.out.print(h[sec-1]+" minute(s) past "+h[hrs-1]);
}
else
{
int r=sec%10;
System.out.print(m[r-1]+" minutes past "+h[hrs-1]);
}
}
}
else
{
int r=sec%10;
System.out.print("twenty "+h[r-1]+" minutes past "+h[hrs-1]);
}
}
}
else
{ //To print the message "minutes to"
int r=60-sec;
if(r==15)
{ if(hrs==12) System.out.print("quarter to one ");
else System.out.print("quarter to "+h[hrs]);
}
else if(r>20)
System.out.print("twenty "+h[(r%10)-1]+" minutes to "+h[hrs]);
else if(r>=11&&r<=20)
System.out.print(m[r-11]+" minutes to "+h[hrs]);
else System.out.print(h[r-1]+" minute(s) to "+h[hrs]);
}
}//main
}//class
//2003 Q.No.3 To find the saddle point and sort the elements along principal //diagonal in
ascending order using insertion sort technique
import java.io.*;
public class Q3_2003
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int N;
int A[][],rowmin[],colmax[];
int i,dia[],m=0,j,flag=0,t,ptr;
System.out.print("INPUT : N= ");
N=Integer.parseInt(b.readLine());;
A=new int[N][N];
rowmin=new int[N];
colmax=new int[N];
dia=new int[N];
System.out.print("MATRIX A[ ] [ ] = ");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
A[i][j]=Integer.parseInt(b.readLine());
}
System.out.print("\nOUTPUT :\n\n");
//To output the matrix elements as given
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{System.out.print(A[i][j]+"\t");
}
System.out.print("\n");
}
//To sort the principal diagonal and find saddle point
int c=0;
//Loop to find minimum no of each row, maximum no each column and store
//them in rowmin[],colmax[]
for(i=0;i<N;i++)
{
int min=A[i][0];
int max=A[0][i];
//Loop to store the principal diagonal elements in dia[]
for(j=0;j<N;j++)
{
if(i==j){dia[m]=A[i][j]; m++; }//end of if
if(A[i][j]<min)
{
min=A[i][j];
}
if(A[j][i]>max)
{
max=A[j][i];
}
}//end of for ‘j’ loop
rowmin[c]=min;
colmax[c]=max;
c++;
}//end of ‘I’ loop
//Loop to find the saddle point
for(i=0;i<c;i++)
{
for(j=0;j<c;j++)
{
if(rowmin[j]==colmax[j])
{
flag=1;
System.out.print("SADDLEPOINT = "+rowmin[j]);
}
}//j loop
if(flag==1)break;
}// I loop
if(flag==0)
System.out.print("\nNO SADDLE POINT\n");
System.out.print("\n\nMATRIX AFTER SORTING THE PRINCIPAL DIAGONAL\n");
//A nested loop to sort the diagonal elements using Insertion sort
for(i=1;i<N;i++)
{
t=dia[i];
ptr=i-1;
while(t<dia[ptr]&&ptr>=0)
{
dia[ptr+1]=dia[ptr];
ptr--;
}
dia[ptr+1]=t;
}
//storing back
m=0;
for(i=0;i<N;i++)
{
A[i][i]=dia[m];
m++;
}
//Loop to print the resultant matrix
for(i=0;i<N;i++)
{
System.out.print("");
for(j=0;j<N;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.print("\n");
}// end of ‘I’ loop
}//main
}//class
//2004 Q.no.1 To input X and Y and calculate the smallest base for X and smallest base //for Y
//To input two integers X and Y and calculate the smallest base for X
//and smallest base for Y(likely different from X) so that X and Y
//represent the same value
/*SAMPLE DATA:
INPUT:
X=12
Y=5 OUTPUT: 12(base 3)=5(base 2)
SAMPLE DATA:
INPUT: X=10 Y=A
OUTPUT: 10(base 2)=A(base 2)*/
import java.io.*;
class Q1_2004
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String a,b;
System.out.print("SAMPLE DATA:\n");
System.out.print("INPUT:\n");
System.out.print("X=");
a=br.readLine();
System.out.print("Y=");
b=br.readLine();
System.out.print("OUTPUT:\n");
int X,Y;
//Statements to convert the alphabet inputs into integers for eg 'A' to 10...
if(Character.isLetter(a.charAt(0))) X=a.charAt(0)-55; else X=Integer.parseInt(a);
if(Character.isLetter(b.charAt(0)))Y=b.charAt(0)-55; else Y=Integer.parseInt(b);
int i,x1=X,y1=Y;int flag=0;
for(i=2;i<=20;i++) //Loop to find the smallest base
{ double s1=0; int c1=0;
//loop to find the sum for each base
while(x1>0)
{
int r=x1%10;
s1=s1+r*Math.pow(i,c1);
c1++; x1=x1/10;
}
//loop to find the base so that X=Y
for(int j=2;j<=20;j++)
{ double s2=0; int c2=0;
while(y1>0)
{
int r=y1%10;
s2=s2+r*Math.pow(j,c2);
c2++; y1=y1/10;
}
if(s2==s1) //Statements to print the desired output
{
if(Character.isLetter(a.charAt(0)))
System.out.print(a.charAt(0)+"(base "+i+")="+Y+"(base "+j+")");
else if(Character.isLetter(b.charAt(0)))
System.out.print(X+"(base "+i+")="+b.charAt(0)+"(base "+j+")");
else System.out.print(X+"(base "+i+")="+Y+"(base "+j+")");
flag=1;break;
}
y1=Y;}
if(flag==1) break; else{x1=X;}
}//i loop
if(flag==0)
System.out.print(X+"is not equal to "+Y+"in any base between 2 to 20");
}//main
}//class
//2004 Q.no.2 To read a coded message and decodes it
//Encoded message 2312179862310199501872379231018117927
//The decoded message will be Have a Nice Day
import java.io.*;
class Q2_2004
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1="",s=""; int i;
System.out.print("SAMPLE DATA:\n");
System.out.print("INPUT:\n");
System.out.print("Encoded message:\n");
s1=br.readLine();
//To reverse the original string
int l=s1.length();
for(i=l-1;i>=0;i--)
{
s=s+s1.charAt(i);
}
//Loop to get the desired output
for(i=0;i<l;i++)
{
//Statements to form a 2 digit number
int a=s.charAt(i)-'0';
int b=s.charAt(i+1)-'0';
int td=a*10+b;
char f=(char)td;
i=i+1;
if(td==32)System.out.print(" ");//Statement to print the blank space blank space ascii value is 32
else if(!Character.isLetter(f))//Statements to extract the 3rd digit if char(td) does
//not represent an alphabet
{
i=i+1;
int d=s.charAt(i)-'0';
int nd=td*10+d;
System.out.print((char)nd);
}
else
{ System.out.print((char)td);//Statement to print the alphabet of the two digit number
}
}//i loop
}//main
}//class
//2004 Q.no.3 To find the duration for which each user has logged.
//Output the record of the user who logged for the longest duration
import java.io.*;
class Q3_2004
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int userid[],N,loginhrs[],loginmin[],logouthrs[];
int logoutmin[],loginday[],loginmon[],i;
int logoutday[],logoutmon[],totalmin[],durhrs[],durmin[];
userid=new int[100];
loginhrs=new int[100]; loginmin=new int[100]; logouthrs=new int[100]; logoutmin=new int[100];
loginday=new int[100]; loginmon=new int[100]; logoutday=new int[100];
logoutmon=new int[100]; totalmin=new int[100]; durhrs=new int[100]; durmin=new int[100];
System.out.print("INPUT:\n");
System.out.print("Number of users: ");
N=Integer.parseInt(b.readLine());
//loop to enter the input as given
for(i=0;i<N;i++)
{
System.out.println("USER IDENTIFICATION ");
userid[i]=Integer.parseInt(b.readLine());
System.out.println("LOGIN TIME ");
loginhrs[i]=Integer.parseInt(b.readLine());
loginmin[i]=Integer.parseInt(b.readLine());
System.out.println("DATE");
loginday[i]=Integer.parseInt(b.readLine());
loginmon[i]=Integer.parseInt(b.readLine());
System.out.println("LOGOUT TIME");
logouthrs[i]=Integer.parseInt(b.readLine());
logoutmin[i]=Integer.parseInt(b.readLine());
System.out.println("DATE\n");
logoutday[i]=Integer.parseInt(b.readLine());
logoutmon[i]=Integer.parseInt(b.readLine());
}
//loop to find the duration for which each user logged
for(i=0;i<N;i++)
{
if(loginday[i]==logoutday[i])
{
totalmin[i]=logouthrs[i]*60+logoutmin[i]-(loginhrs[i]*60+loginmin[i]);
durhrs[i]=totalmin[i]/60;
durmin[i]=totalmin[i]%60;
}
else
{
totalmin[i]=1440-(loginhrs[i]*60+loginmin[i]);
for(int j=loginday[i]+1;j<logoutday[i];j++)
{
totalmin[i]=totalmin[i]+1440;
}
totalmin[i]=totalmin[i]+logouthrs[i]*60+logoutmin[i];
durhrs[i]=totalmin[i]/60;
durmin[i]=totalmin[i]%60;
}
}//i loop
int large=totalmin[0];
int pos=0;
//loop to find the index of the user who logged for the longest duration
for(i=1;i<N;i++)
{
if(totalmin[i]>large)
{
large=totalmin[i];
pos=i;
}
}//i loop
System.out.print("OUTPUT:\n");
System.out.print("USER IDENTIFICATION LOGIN TIME&DATE LOGOUT TIME &DATE\t");
System.out.print("DURATION HOURS:MINS\n");
//loop to output all records along with the duration in hrs:min
for(i=0;i<N;i++)
{
System.out.print("\t"+userid[i]+"\t"+loginhrs[i]+":"+loginmin[i]+"\t");
System.out.print(loginday[i]+"-"+loginmon[i]+"\t\t"+logouthrs[i]+":"+logoutmin[i]);
System.out.print("\t"+logoutday[i]+"-"+logoutmon[i]+"\t\t"+durhrs[i]+":");
System.out.print(durmin[i]+"\n");
}
if(f==1)
System.out.print("\nValid!");
} }
}
}
//2007 Q.no.3 Program to determine the unique digit integers in the range
//between m and n (both inclusive) and output them
import java.io.*;
class Q3_2007
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int a[]={0,0,0,0,0,0,0,0,0,0};
int m,n;
System.out.print("INPUT\n");
System.out.print("m=");
m=Integer.parseInt(b.readLine());
System.out.print("n=");
n=Integer.parseInt(b.readLine());
System.out.print("\nOUTPUT:\n");
System.out.print("THE UNIQUE DIGIT INTEGERS ARE:-\n");
int freq=0;
//loop to print unique digit integers in the range m and n
for(int i=m;i<=n;i++)
{
int no=i,f=1;
//loop to increment each digit's counter
while(no>0)
{
int r=no%10;
a[r]++;
no=no/10;
}
//loop to check each digit's frequency
for(int j=0;j<10;j++)
{
if(a[j]>1)
{f=0;break;}
}
//condition to print unique digit integer
if(f==1)
{
System.out.print(i+",");
freq++;
}
//loop to initialize the counter
for(int j=0;j<10;j++)
{
a[j]=0;
}
}//I loop end
System.out.print("\nFREQUENCY OF UNIQUE-DIGIT INTEGERS IS:"+freq);
}
}
}
}
//Print the desired output
System.out.println("Sentence No of vowels No of words");
for(int i=0;i<k;i++)
{
System.out.println((i+1)+"\t"+vowels[i]+"\t"+now[i]);
}
System.out.println("Sentence No of words/vowels");
for(int i=0;i<k;i++)
{
System.out.print((i+1)+"\t\t");
for(int j=1;j<=3*vowels[i];j++)
System.out.print("V");
System.out.println();
for(int j=1;j<=3*now[i];j++)
System.out.print("W");
System.out.println();
}
}//end of main
}//end of class
/* Q1-2009 Design a program to accept a day number between 1 to 366, year(in 4 digits) from the
user to generate and display the corresponding date. Also accept 'N'(1<=N<=100) from the user
to compute and display the future date corresponding to 'N' days after
* the generated date.
* Example:
* INPUT
* DAY NUMBER:360
* YEAR:2008
* DATE AFTER N:10
* OUTPUT
* 25TH DECEMBER 2008
* DATE AFTER 10 DAYS: 4TH JANUARY 2009 */
import java.io.*;
public class day1
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int d[]={31,28,31,30,31,30,31,31,30,31,30,31};
String mon[]={"Jan","Feb","Mar","APr","May","June","July","Aug","Sep","Oct","Nov","Dec"};
int day,y,N;
System.out.print("DAY NUMBER :");
day=Integer.parseInt(b.readLine());
System.out.print("YEAR ");
y=Integer.parseInt(b.readLine());
System.out.print("DATE AFTER(N) ");
N=Integer.parseInt(b.readLine());
boolean flag=false;
//to check the leap year
if(y%400==0 || (y%4==0 &&y%100!=0)){ d[1]=29;flag=true;}
System.out.println("OUTPUT");
int sum=0,i;
//if statement to print the suffix
for(i=0; ;i++)
{ if(sum+d[i]>day)break;
sum=sum+d[i];
}
int d1=day-sum;
System.out.print(d1);
//if statement to print the suffix
if(d1==1||d1==21||d1==31)
System.out.println("ST "+mon[i]+"\t"+y);
else if(d1==2||d1==22)
System.out.println("ND "+mon[i]+"\t"+y);
else if(d1==3||d1==23)
System.out.println("RD "+mon[i]+"\t"+y);
else
System.out.println("TH "+mon[i]+"\t"+y);
System.out.print("DATE AFTER "+N+" DAYS : ");
int daf=day+N;
//if date exceeds 1 year after N days
if(daf>366&&flag==true){day=daf-366;y=y+1;}
else if(daf>365&&flag==false){day=daf-365;y=y+1;}
else day=daf;
sum=0;
//loop to determine the corresponding date
for(i=0; ;i++)
{ if(sum+d[i]>day)break;
sum=sum+d[i];
}
d1=day-sum;
System.out.print(d1);
//if statement to print the suffix
if(d1==1||d1==21||d1==31)
System.out.println("ST "+mon[i]+"\t"+y);
else if(d1==2||d1==22)
System.out.println("ND "+mon[i]+"\t"+y);
else if(d1==3||d1==23)
System.out.println("RD "+mon[i]+"\t"+y);
else
System.out.println("TH "+mon[i]+"\t"+y);
}
}
/* 2009.Q2. Allow the user to input positive integers in the matrix of maximum size 20.
* 1.sort the elements of the outer row and column elements in ascending order
* 2.calculate the sum of the outer row and column elements............ */
import java.io.*;
class Q2_2009
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int A[][],OUT[],M,N,c=0,i,j,k,sum=0;
System.out.print("M=");
M=Integer.parseInt(b.readLine());
System.out.print("N=");
N=Integer.parseInt(b.readLine());
A=new int[M][N];
OUT=new int[M*N];
//Loop to enter the matrix elements
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
A[i][j]=Integer.parseInt(b.readLine());
}
//loops to extract the boundary elements from the matrix and storing them to OUT[ ]
if(M==N)
{
for(i=0;i<M;i++)
{
OUT[c]=A[0][i];c++;
}
for(k=1,j=N-1;k<N;k++)
{
OUT[c]=A[k][j];c++;
}
for(k=N-2,j=N-1;k>=0;k--)
{
OUT[c]=A[j][k];c++;
}
for(k=0,j=N-2;j>0;j--)
{
OUT[c]=A[j][k];c++;
}
}//if
//bubble sort the outer elements and adding the boundary elements
for(i=0;i<c-1;i++)
{
for(j=0;j<c-1;j++)
{
if(OUT[j]>OUT[j+1])
{
int t=OUT[j];
OUT[j]=OUT[j+1];
OUT[j+1]=t;
}
}
}//I loop
c=0;
//loops to store back the sorted boundary elements into A[][]
for(i=0;i<M;i++)
{
A[0][i]=OUT[c];c++;
}
for(k=1,j=N-1;k<N;k++)
{
A[k][j]=OUT[c];c++;
}
for(k=N-2,j=N-1;k>=0;k--)
{
A[j][k]=OUT[c];c++;
}
for(k=0,j=N-2;j>0;j--)
{
A[j][k]=OUT[c];c++;
}
System.out.println();
//loop to print the rearranged matrix
System.out.println("REARRANGED MATRIX");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.println();
}
//loop to print the boundary elements of the matrix
System.out.println("BOUNDARY ELEMANTS");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
if((i!=0&&j!=0)&&((i==j)||(i+j==(N-1)))&&(i!=N-1&&j!=N-1) )
{System.out.print("\t");
}
else
{sum=sum+A[i][j];System.out.print(A[i][j]+"\t");}
}
System.out.println();
}//i
System.out.print("SUM OF THE OUTER ROW AND COLUMN ELEMENTS = "+ sum);
}//main
}//class
//Q3.2009.//INPUT :The lines are printed in reverse order
//OUTPUT:In the are lines order printed reverse
import java.io.*;
class Q3_2009
{
public static void main()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a sentence\n");
String s=b.readLine();
int i=0,count=0;
String words[]=new String[20];
//to avoid printing the word null
for(i=0;i<20;i++)
words[i]="";
s=s+" ";//for the last word
int l=s.length();
//loop to extract the words and store them in words[]
for(i=0;i<l;i++)
{ char c=s.charAt(i);
if(s.charAt(i)!=' ')
{words[count]=words[count]+c;}
else
{
count++;
}
}
//loop to arrange the words in ascending order of their length
for(i=0;i<count-1;i++)
{
for(int j=0;j<count-1;j++)
{
if(words[j].length()>words[j+1].length())
{
String t=words[j];
words[j]=words[j+1];
words[j+1]=t;
}
}
}
//loop to print the arranged words
for(i=0;i<count;i++)
{ for(int j=0;j<words[i].length();j++)
{
if(i==0&&j==0)
System.out.print(Character.toUpperCase(words[i].charAt(0)));//to print the first letter of first
word in upper case
else
System.out.print(Character.toLowerCase(words[i].charAt(j)));
}
System.out.print(" ");
}
}
}
int k=0;
//Loop to extract the sentences
for(int i=0;i<l;i++)
{
if(s.charAt(i)=='.'||s.charAt(i)=='?'||s.charAt(i)=='!')
{
a[k]=a[k]+s.charAt(i);
i++;//to avoid storing the leading blank space in a sentence
k++;
}
else
{
a[k]=a[k]+s.charAt(i);
}
}
int c=0;
for(int i=0;i<k;i++)
{
String senw[]={"","","","",""};
a[i]=a[i]+" ";//to extract the last word of the sentence a[i]
int len=a[i].length();
for(int m=0;m<len;m++)
{
if(a[i].charAt(m)!=' ')
{ senw[c]=senw[c]+a[i].charAt(m);}
else
{ c++;
}
}
for(int j=0;j<c-1;j++)//to sort the words in alphabetical order using bubble sort of senw[ ] array
{
for(int k1=0;k1<c-1;k1++)
{ //not to compare the special characters
if((senw[k1].compareToIgnoreCase(senw[k1+1])>0)&&
Character.isLetter(senw[k1+1].charAt(0)))
{
String t=senw[k1];
senw[k1]=senw[k1+1];
senw[k1+1]=t;
}
}
}
//Loop to print the arranged words
for(int h=0;h<c;h++)
System.out.print(senw[h]+" ");
c=0;
}// i loop
}//main
}//class