You are on page 1of 60

AIM: 1. Write a java program to find the sum of both diagonal elements of a matrix.

Sample Data:Enter the matrix : 5 3 7 2 1 4 8 7 2 The sum of first diagonal is: 8 The sum of second diagonal is: 16 ALGORITHM Step 1 – Declare and initialize the required variables like i,j,a[] Step 2 – Get the size of the matrix. Step 3 – Get the elements of the matrix Step 4 – Begin loop i from 0 to n-1 Step 6 – Find the sum1 using the formula sum1=sum1+a[i][i]. Step 7–Begin loop j from 0 to n-1 Step 8 – Find the sum2 using the formula sum2=sum2+a[(n-j-1)][(n-j-1)]; Step 9 – print sum1 and sum2 Step 10 – End the process PROGRAM import java.io.*; class diagonalmatrix { public static void main(String args[])throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the no: of columns"); int n=Integer.parseInt(bf.readLine()); int a[][]=new int[n][n] ; int i,j; System.out.println("enter the matrix"); for( i=0;i<n;i++) { for(j=0;j<n;j++) { a[i][j]=Integer.parseInt(bf.readLine()); } } int sum1=0; for(i=0;i<n;i++) { sum1=sum1+a[i][i]; } int sum2=0;

for(j=0;j<n;j++) { sum2=sum2+a[(n-j-1)][(n-j-1)]; } System.out.println("The sum of first diagonal is :"+sum1); System.out.println("The sum of second diagonal is:"+sum2); }} VARIABLE DESCRIPTION riable Name a[][] n sum1,sum2 i, j Data Type Integer array Integer Integer Integer, Integer Purpose To store the first array for multiplication To store the size of array To store the sum of the elements of the 2 diagonals Loop variables

OUTPUT enter the matrix dsg enter the no: of columns 3 enter the matrix 1 2 3 4 5 6 7 8 9 The sum of first diagonal is :15 The sum of second diagonal is:15

AIM: 2. Write a menu driven program to implement a 4-function calculator. The user should be able to select the options corresponding to the four operations, i.e. addition, subtraction, multiplication or division, and then enter the two numbers for the operation. The result of the calculation should be displayed as the output. The four operations should be done in four different functions. The arguments of the functions will be the two numbers on which the operation has to be performed and the result will be the return value. Sample data :Menu 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter your choice (1, 2, 3, 4 or 5) 3 Enter the first number 5 Enter the second number 3 Product = 15 ALGORITHM Step 1- create a object named obj Step 2 – Enter the choice Step 3 – Enter the two numbers . Step 4 – call function according to the given choice Step 6 –execute the function and print the result Step 7–call main function again Step 8 – End the process if choice is 5

PROGRAM import java.io.*; class calculator { public void addition(int a,int b) { int sum=a+b; System.out.println("sum:"+sum); } public void subtraction(int a,int b) { int difference=a-b;

out. else if(ch==3) obj.out. System. System.multiplication(a.Division").println(" 2.out.Addition"). int remainder=a%b. System.println(" 4.division(a. else if(ch==2) obj.println("product:"+product).main(). 3. System. } public void multiplication(int a.parseInt(bf.subtraction(a. System.readLine()). } public void division(int a. if(ch==1) obj. int ch=Integer.println("enter the 1st number").out.println(" 5.Exit").out. BufferedReader bf=new BufferedReader(new InputStreamReader(System.out.b).Multiplication"). } public static void main()throws IOException { calculator obj=new calculator(). int a=Integer.readLine()). System. obj. System.println("the answer after dividing is:"+quotient+" "+remainder+"/"+b).Substraction").parseInt(bf.out. 2.addition(a.out. int b=Integer. System.int b) { int product=a*b.out.out.b).println(" 1.b).println(" difference:"+difference).b).out. System. } } } VARIABLE DESCRIPTION riable Name ch a.parseInt(bf.println(" 3. if(ch!=5) { System. 4 or 5) ").int b) { int quotient=a/b.println("enter your choice(1.b Data Type Integer Integer Purpose To store the choice of the user To store the 2 numbers .in)). else if(ch==4) obj.readLine()).System.println("enter the 2nd number").

Multiplication 5.OUTPUT 1. 3.Addition 2.Exit enter your choice(1. 2.Substraction 3. 3.Division 4.Substraction 3. 4 or 5) 5 . 4 or 5) 3 enter the 1st number 5 enter the 2nd number 2 the answer after dividing is:2 1/2 1.Addition 2.Multiplication 5.Exit enter your choice(1. 2.Division 4.

in)). int beg=0.n.Write a program to reverse all strings in an array Sample Input :Enter the string : Happy Birthday Sample Output :The changed string is : yppaH yadhtriB ALGORITHM Step 1 – Declare and initialize the required variables like m.out. break.beg. } else if (str. int i.charAt(i)==' ') { .out. int m=0.length()) { s[m]=str.k. String str=bf. String reverseStr = new StringBuffer(s[m]). String pop.println("Enter the sentence").substring(beg.io. Step 3 – Begin loop i from 0 to length of the string Step 4 – when i becomes equal to the length Step 6 – the last word is reversed and printed Step 7– when the character at index is a space Step 8 – each word is reversed and printed Step 9 – End the process PROGRAM import java.length(). System. String s[]=new String[50]. class hello { public static void main(String args[])throws IOException { hello obj=new hello().readLine().*.pop.i++) { if(i==str.I. for(i=0.print(reverseStr+" ").reverse().s[] Step 2 – enter the string. System.i<=str.toString(). BufferedReader bf=new BufferedReader(new InputStreamReader(System.AIM: 4.i).

substring(beg. String reverseStr = new StringBuffer(s[m]). System.s[m]=str.print(reverseStr+" ").toString().reverse().out.i). m++. } } }} VARIABLE DESCRIPTION variable Name s[] m beg i. Data Type String array Integer Integer Integer Purpose To store the word in the input string in a string array To store the index of the array To store the index of the first letter of each word Loop variable OUTPUT Enter the sentence my name is noel ym eman si leon . beg=i.

for(i=0.readLine()).i<n. } System.io.Program to insert elements into a sorted array at an appropriate location Sample Data :Enter the number of elements in the array : 6 Enter the elements of the array : 3 5 6 8 11 14 Enter the element to be inserted : 9 The array after insertion of the element is : 3 5 6 8 9 11 14 ALGORITHM Step 1 – Declare and initialize the required variables like and j. for(i=0.in)).j.parseInt(bf.println("enter the elements of the array").*.print the rest of the array Step 10-end process PROGRAM import java.out.AIM: 5. Step 8 – print the input number Step 9. int n=Integer.println("enter the element to be inserted"). Step 7 – if the entered number is lesser than the number at index i. print array till there.i++) { a[i]=Integer.parseInt(bf.i++) { .readLine()).out.readLine()).parseInt(bf.i<n. int x=Integer. class pro5 { public static void main(String args[])throws IOException { int i. Step 2 – enter the size of the array Step 3 – Begin loop i from 0 to n-1 Step 4 – Get the elements of the array Step 5 – Begin loop i from 0 to n-1 Step 6 –enter the number to be entered.println("enter the number of elements in the array"). System. int a[]=new int[n].out. System. BufferedReader bf=new BufferedReader(new InputStreamReader(System.

j<=(i-1).if(a[i]>x) { int b[]=new int[(n+1)].j<n.out.print(x). for(j=i.out. } System.print(a[j]).j++) { System. Integer Purpose To store the array To store the number of elements in the array To enter the number Loop variables OUTPUT enter the number of elements in the array 5 enter the elements of the array 1 6 7 5 9 enter the element to be inserted 4 146759 . j Data Type Integer array Integer Integer Integer. }break.j++) { System.} }}} VARIABLE DESCRIPTION Variable Name a[] n x i.out.print(a[j]). for(j=0.

print( a +".out. i. b and c to the next adjacent value Step 7 – Print d. 3. for(i=4.c d Data Type Integer Integer Purpose To store the numbers that must b added to get next To store the value of the next number in the series . 6. b and c Step 6 – change the value of a.d=3 Step 2 – Enter the number of terms n( parameter)." + d). b=c. The number of terms required is to be passed as parameter ALGORITHM Step 1 – Declare and initialize the required variables like a=0. System.Write a java program to print the tribonacci series (i. "+ b + ". 20. a=b. "+c).i++) { d=a+b+c.i<=n. d=0. b=1. 1.AIM: 6. c=d.e.out. 11. and87 Step 5 – find d by adding a. Step 3 – print the first three numbers Step 4 – Begin loop i from 4 to n and repeat step 6. Step 8 – End the process PROGRAM public class pro6 { void func(int n) { int a=0. 2.b=1. 0. 27). c= 2.c=2.b. } } } VARIABLE DESCRIPTION Variable Name a.print(". System.

37.11.20.6.68. 2. Integer Loop variable OUTPUT (When n=10) 0.i. 1.3.125 .

increase m by 1. Write a Java program to input a number and print its primordial.6 and 7 Step 5 – Begin loop j from 2 to i-1 and repeat step 6 Step 6 – when i is completely divisible by j .io.e. m=0. } if(m==0) . Step 2 – enter the number Step 3 – Begin loop i from n to 1 and repeat steps 5.parseInt(bf. [Primordial (P#) is defined to be the product of prime numbers less than or equal to p] Sample Data:Enter a number: 3 3# = 2 x 3 = 6 Enter a number: 13 13# = 2 x 3 x 5 x 7 x 11 x 13 = 30030 ALGORITHM Step 1 – Declare and initialize the required variables like i.AIM: 7. class pro7 { public static void main(String args[])throws IOException { int i.println("enter a number"). int n=Integer.in)). Step 7 – if m is 0 then it is prime so multiply it with product Step 8 –print product Step 9-End process PROGRAM import java. pro=1.out.*.j++) { if((i%j)==0) m++. i. n#.readLine()). int m=0. int pro=1. for( i=n.i>0.j<i. System. BufferedReader bf=new BufferedReader(new InputStreamReader(System.i--) { for(int j=2.

out.{pro=pro*i.println(pro). j Integer Integer.} m=0. }} VARIABLE DESCRIPTION Variable Name n m Data Type Integer Integer Purpose To store the input number To store the number of numbers with which the input number can be divided To store the product Loop variables pro i.} System. Integer OUTPUT enter a number 13 30030 .

3.it is first broken apart before adding) Step 6 – now sum of all the numbers in the input is added 1 by 1. Example : (i) 666 Prime factors are 2. 3 and 37 Sum of digits = (6 + 6 + 6) = 18 Sum of digits of the factors = (2 + 3 + 3 + (3 + 7)) = 18 (ii) 4937775 Prime factors are 3. 121. 58. (ISC Practical 2008) ALGORITHM Step 1 – Declare and initialize the required variables like num. int sum1=0. int sum=0.AIM: 8. Examples of Smith numbers are 4. A Smith number is a composite number. 5.i. Step 2 Enter the value as a parameter.…….i. 85. .sum1=1. Step 7 – check if the 2 sums are the same Step 8 – if yes print a positive test result .n. the sum of whose digits is the sum of prime factors obtained as a result of prime factorization (excluding 1). Step 4 – Begin loop i from 2 to n Step 5 – sum is now added with the new number(if the number is grater than 10. 94.numb.k. 27.pro. 22.sum=0.k.otherwise negative Step 9-end process PROGRAM class pro8 { public static void main(int n) { int num. Step 3 – Get the elements of the two matrices. 5 and 65837 Sum of digits = (4 + 9 + 3 + 7 + 7 + 7 + 5) = 42 Sum of digits of the factors = ( 3 + 5 + 5 +(6 + 5 + 8 + 3 + 7)) = 42 ] Write a program to input a number and display whether the number is a Smith number or not.

} }} while(num!=0) { numb=num%10. i=2. } else { System. n=n/10.i<=n. } } else{ sum=sum+i. int pro. num i Data Type Integer Integer Integer .out. sum1=sum1+numb. for(i=2.int numb. num=n.println("it is a smith's number"). num=num/10. } if(sum1==sum) { System. sum=sum+numb.Integer Integer Purpose To store the sum of the factors To store the sum of the numbers the input number To store the number Loop variable . }}} VARIABLE DESCRIPTION Variable Name Sum Sum1 n.println("it is not a smith's number").out. n=n/i.i++) { if(n%i==0) { if(i>10) { while(n!=0) { numb=n%10.

OUTPUT (when n is4937775) it is a smith's number .numb Integer To store the number to be added 1by 1.

AIM: 9. Write a program to declare a matrix A [][] of order (MXN) where „M‟ is the number of rows and „N‟ is the number of columns such that both M and N must be greater than 2 and less than 20. Allow the user to input integers into this matrix. Perform the following tasks on the matrix:    Display the input matrix. Find the maximum and minimum value in the matrix and display them along with their position. Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix and then output the rearranged matrix.

Sample Data:M=3 N=4 Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4 Original matrix: 8 7 9 3 -2 0 4 5 1 3 6 -4 Largest Number: 9 Row: 0 Column: 2 Smallest Number: -4 Row=2 Column=3 Rearranged matrix: -4 -2 0 1 3 3 4 5 6 7 8 9 (ISC Practical 2012) ALGORITHM Step 1-declare the variables like r,c, maxi,maxj,mini,minj,i,j,m,n,arr[][],bool.

Step 2-get the number of columns and rows of the matrix.check if the matrix has required size. Step 3-input the elements in the array. Step 4-print the array, the smallest and largest number,and its index. Step 5-sort the array. Step 6-print the new array. PROGRAM import java.io.*; class Matrix { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int arr[][]; int r,c,max,min,maxi,maxj,mini,minj,i,j,m,n; public void take()throws Exception { boolean bool=true; while(bool) { System.out.println("\nEnter the number of rows:"); r=Integer.parseInt(br.readLine()); System.out.println("\nEnter the number of columns:"); c=Integer.parseInt(br.readLine()); if(r<2 || c<2 || r>20 || c>20) bool=true; else bool=false; } arr=new int[r][c]; for(i=0;i< r;i++) { for(j=0;j< c;j++) { System.out.println("\nEnter Value:"); arr[i][j]=Integer.parseInt(br.readLine()); } } max=arr[0][0]; min=arr[0][0]; maxi=0; mini=0; maxj=0; minj=0; for(i=0;i< r;i++) { for(j=0;j< c;j++)

{ if(arr[i][j]>max) { max=arr[i][j]; maxi=i; maxj=j; } else if(arr[i][j]< min) { mini=i; minj=j; min=arr[i][j]; } } } System.out.println("\nOriginal Array\n"); for(i=0;i< r;i++) { for(j=0;j< c;j++) { System.out.print(arr[i][j]+" "); } System.out.println(); } System.out.println("\nMaximum Value="+max); System.out.println("\nRow="+maxi); System.out.println("\nColumn="+maxj); System.out.println("\nMinimum Value="+min); System.out.println("\nRow="+mini); System.out.println("\nColumn="+minj); for(m=0;m< r;m++) { for(n=0;n< c;n++) { for(i=0;i< r;i++) { for(j=0;j< c;j++) { if(arr[m][n]< arr[i][j]) { min=arr[m][n]; arr[m][n]=arr[i][j]; arr[i][j]=min; } } } } }

j Maxi. minj min Data Type Integer Integer Integer array Integer. Integer Integer. Integer Integer Purpose To store the number of rows To store the number of columns To store the sum of input matrix Loop variables To store the index of the maximum value To store the index of the minimum value To store temporary variable while sorting OUTPUT Enter the number of rows: 2 Enter the number of columns: 2 Enter Value: 2 .out.System.maxj Mini.print(arr[i][j]+" ").i< r. Integer Integer. } } public static void main(String args[]) throws Exception { Matrix ob=new Matrix().j< c.i++) { for(j=0.println("\nSorted Array\n"). for(i=0.out.take().j++) { System. } } VARIABLE DESCRIPTION Variable Name r c arr[][] i.println().out. ob. } System.

Enter Value: 1 Enter Value: 3 Enter Value: 4 Original Array 21 34 Maximum Value=4 Row=1 Column=1 Minimum Value=1 Row=0 Column=1 Sorted Array 12 34 .

print the numbers. write a program to determine how many prime-palindrome integers are there in the range between m and n (both inclusive) and output them.787. Step 7-end process.929 Frequency of prime palindrome integers: 15 INPUT: m=100 n=5000 OUTPUT: Out of Range (ISC Practical 2012) ALGORITHM Step 1-initailise variables like m. A prime palindrome integer is a positive integer (without leading zeros) which is prime as well as a palindrome.383. Step 6-if yes.313.757. Step 2-input and check the range.351. Step 3-begin loop in the given range.151.373. Step 5-reverse the number and check if they are palindromes.n and c.919.131. Display the number of prime palindrome integers in the specified range along with their values in the format specified below: Test your program with the sample data and some random data: Sample Data:INPUT: m=100 n=1000 OUTPUT: The prime palindrome integers are: 101. where m < n. Step 4.181. Given two positive integers m and n.797. .AIM: 10.727.check if the number is a prime number. The input contains two positive integers m and n where m< 3000 and n< 3000.191.

io.out. } System. } } private boolean palPrime(int x) { boolean bool=false.readLine()). m=Integer.parseInt(br. class PalPrime { BufferedReader br=new BufferedReader(new InputStreamReader(System. "+m). for(i=2. public void showPalPrime() throws Exception { c=0. else System.out.out.println("Out of Range. n=Integer. c++.println("\nFrequency of Prime Palindrome integers: "+c).i++) { if(x%i==0) break. int rev=0.*. int m.print(m).PROGRAM import java.out. int i. System. else { System.println("Enter the Lower Limit:").").out. System.println("The Prime Palindrome integers are:").print(". } m++.in)). int c. .parseInt(br.println("Enter the Upper Limit:").n. while(m<=n) { if(palPrime(m)) { if(c==0) System.out.i< x. if(m>=n || n>=3000) System.readLine()).out.

if(bool) { for(i=x. 353.showPalPrime().i>0. 787.n c sum[][] i. 313.i=i/10) { rev=rev*10+i%10. ob.n2 Data Type Integer Integer Integer array Integer. 727. } public static void main(String args[]) throws Exception { PalPrime ob=new PalPrime (). } if(rev!=x) bool=false. } } VARIABLE DESCRIPTION Variable Name m. Integer Integer Integer. 797. Integer Purpose To store the upper and lower limit To store the frequency of the prime palindrome integers To store the sum of the two matrices entered Loop variables To store the reversed number To store the size of second array OUTPUT Enter the Lower Limit: 100 Enter the Upper Limit: 1000 The Prime Palindrome integers are: 101. 919. } return bool.} if(i==x) bool=true. 757. 191. 929 . 151. 131. 181. j rev m2. 383. 373.

Frequency of Prime Palindrome integers: 15 .

5. The available denomination with the bank are of rupees 1000. Sample Data:INPUT: 14836 OUTPUT: ONE FOUR EIGHT THREE SIX DENOMINATION: 1000 X 14 =14000 500 X 1 =500 100 X 3 =300 50 X 1 =50 5 X 1 =5 1 X 1 =1 INPUT: 235001 OUTPUT: INVALID AMOUNT (ISC Practical 2010) ALGORITHM Step1-Declare the variables like rev. [Note: only the denomination used should be displayed]. Design a program to accept the amount from the user and display the break-up in descending order of denominations.out. Step4-find the denominations.20.50.*.2 and 1. Step5-print the denominations. PROGRAM import java.amount.10.e preference should be given to the highest denomination available) along with the total number of notes.in)). upto 5 digits.dummy.100.dummy Step2-input amount and check if it is less than100000. BufferedReader br=new BufferedReader(new InputStreamReader(System.println("Enter the Amount:"). Also print the amount in words according to the digits. (i.500.if yes. Step4-begin loop till the whole of the numbers is written in words. A bank intends to design a program to display the denomination of an input amount. public void intake() throws IOException { System.amount. . reverse the number. class Bank { int rev=0.io. Step3.AIM: 12.

break.out. break. break. case 6: System.print(" TWO").out..print(" ZERO").parseInt(br.println("Invalid Amount. break.out. case 7: System.out."). return.amount=Integer.print("Amount in words :"). case 1: System. case 5: System. break.out. if(amount >99999) { System. } dummy=amount.print(" NINE"). } System.out. while(dummy >0) { rev=rev*10+dummy%10.out. case 8: System.print(" EIGHT").print(" SIX"). break. break.out..print(" FOUR"). } rev=rev/10.print(" ONE").readLine()).print(" FIVE"). break. case 9: System.out. while(rev >0) { switch(rev%10) { case 0: System. dummy=dummy/10. case 3: System.print(" SEVEN"). break.out.out. break.print(" THREE"). case 4: System. case 2: System. } .out.

if(rev!=0) System.println("5 X " + rev + " = " + rev*5). rev=amount/500. rev=amount/1000.println("500 X " + rev + " = " + rev*500). amount=amount%500.println("1 X " + rev + " = " + rev*1). rev=amount/2.out. amount=amount%2. rev=amount/5. amount=amount%1000. amount=amount%5. if(rev!=0) System.out. if(rev!=0) System.out. amount=amount%50.System.println("10 X " + rev + " = " + rev*10).out.println("\nDENOMINATORS:\n"). rev=amount/20. if(rev!=0) System.out. rev=amount/50.out.out. if(rev!=0) System. rev=amount/10. and also to find the number of notes To store the amount To store a copy of the amount . if(rev!=0) System. } } VARIABLE DESCRIPTION Variable Name rev Amount Dummy Data Type Integer Integer Integer array Purpose To reverse the amount.out. rev=amount/100. amount=amount%20. if(rev!=0) System. amount=amount%10.println("20 X " + rev + " = " + rev*20).println("2 X " + rev + " = " + rev*2). rev=amount/1.println("50 X " + rev + " = " + rev*50). if(rev!=0) System.println("1000 X " + rev + " = " + rev*1000).out. if(rev!=0) System.out.println("100 X " + rev + " = " + rev*100). amount=amount%100.

Sample Data:INPUT: "This is human resource department. PROGRAM . INPUT: "To handle yourself use your head and to handle others use your heart. The words in this string are assumed to be separated by one or more blanks.str2. Step2-input the sentence.j. Step3-store the words in sr[] and sort.flag." OUTPUT: Yourself Handle Handle Others Heart Head Your Your And Use Use To To. Arrange the words of the input string in descending order of their lengths. Test your program for the following data and some random data. Write a program which takes a string (maximum 80 characters) terminated by a full stop.OUTPUT Enter the Amount: 66542 Amount in words : SIX SIX FIVE FOUR TWO DENOMINATORS: 1000 X 66 = 66000 500 X 1 = 500 20 X 2 = 40 2X1=2 AIM: 13.str.sr[].and check if it satisfies the given conditions. Each word must start with an uppercase letter and the sentence should be terminated by a full stop.x. Step4-print the words. (ISC Practical 2005) ALGORITHM Step1-delcare and initialize variables like I." OUTPUT: Department Resource Human This Is.

").charAt(i). BufferedReader br=new BufferedReader(new InputStreamReader(System.in)). continue.io. str2=str2+ch. if(i==0) str2=str2+(char)(ch-32).i< x. String sr[]. str2="".j.length() >80) { System.substring(0. continue.out.trim(). int i.str2.length()-1)!='.x. class Program1 { String str. else if(ch==' ') { flag=1.str.util.i++) { ch=str.length()-1).println("\nString exceeds 80 characters. } else if(flag==1) { flag=0. } . str2=str2+(char)(ch-32).charAt(str.out.*."). while(true) { System. StringTokenizer stk. int flag. str=br. } str=str. } else break. } if(str.length().out.println("\nString must terminate with full stop.*.println("\nEnter the sentence:"). import java.') { System. public void takeString()throws Exception { char ch. flag=0. if(str.import java. for(i=0. x=str.readLine().

i< x-1.length()) { str2=sr[i].i++) { for(j=i+1.print(". sr[x++]=str2. sr=new String[x]. } public static void main(String args[])throws Exception { Program1 ob=new Program1(). } display().countTokens().out. } } } for(i=0.length()< sr[j]. } System. } private void display() { for(i=0.nextToken().").j< x.else str2=str2+ch.i++) { if(i!=x-1) System.takeString(). sr[i]=sr[j]. else System.i< x.trim().print(sr[i]+" "). x=0. } str=str2.out. sr[j]=str2.hasMoreTokens()) { str2=stk. while(stk. stk=new StringTokenizer(str).out. ob.j++) { if(sr[i].j Data Type Integer Purpose Loop variables . x=stk.print(sr[i]). } } VARIABLE DESCRIPTION Variable Name Int i.

x. Step5.str str2 Sr[] x Integer Integer array String array Integer To store the string To store the sorted array To store the words To store the length and number of tokens OUTPUT Enter the sentence: my name is noel. . Name Noel Is My.leap1. see if it is leap year. Sample Data:Input Date : 29/5/2011 Day on 1st January of that year : SATURDAY Output Day on 29/5/2011 : SUNDAY (ISC Practical 2007) ALGORITHM Step1-intialize the array arr[] and declare the other variables like day.day1.mon. Step4-if month si greater than 2. Write a program to accept a date in the string format dd/mm/yyyy and accept the name of the day on 1st of January of the corresponding year. Find the day for the given date.yr. AIM: 14.I. Step2-Enter the date Step3-store the numerical day month and year in the variables. Step5-find the day of the input date and print it.enter the first day of year.

30.31. } Date1 () { br=new BufferedReader(new InputStreamReader(System. BufferedReader br.31. class Date1 { int arr[]={31.parseInt(day. dayno=Integer.31.trim(). PROGRAM import java. if(mon>2) leap1=leap(yr).substring(0. mon=Integer.take(). public static void main(String args[])throws IOException { Date1 ob=new Date1 (). day=day.println("Enter the Day on 1st January in this year:").31.Step6-end process. else return 0.*.day.substring(i+1).substring(0.yr.leap1.mon. ob.readLine(). System. String str1.show().parseInt(day).out.i)).30. } int leap(int p) { if(p%100==0 && p%400==0) return 1. leap1=0.30.31. } void show () { if (str1. i=day. i=day.equalsIgnoreCase("Sunday")) . day1=day.dayno.28.i)).31}. yr=Integer.indexOf("/"). day=day. day=br.i. } public void take()throws IOException { System.out. ob.println("Enter the date ( in dd/mm/yyyy) format:").trim().io. int x.substring(i+1).in)).day1. str1=br.parseInt(day.indexOf("/").readLine().30. else if(p%100!=0 && p%4==0) return 1.

dayno=dayno+leap1.out. break.i< mon-1. else if (str1. } } } .out.equalsIgnoreCase("Friday")) x=6. else if (str1. case 2: System. break.out. break. case 4: System.println("Wednesday").println("Sunday").equalsIgnoreCase("Monday")) x=2. break.println("Tuesday").equalsIgnoreCase("Saturday")) x=7.i++) dayno=dayno+arr[i].out.i< dayno-1. case 5: System.out.println("Saturday"). case 7: System.out.println("Friday").equalsIgnoreCase("Wednesday")) x=4. break. for(i=0.println("Thursday"). case 6: System.equalsIgnoreCase("Thursday")) x=5. else if (str1.x=1. break. else if (str1. else if (str1.out. else if (str1.i++) { x++. for(i=0.println(day1+ ":"). break. switch(x) { case 1: System. case 3: System.equalsIgnoreCase("Tuesday")) x=3.println("Monday").out. } System. if(x==8) x=1.

VARIABLE DESCRIPTION Variable Name arr[] day Str1 Day1 x dayno i mon yr Leap1 OUTPUT Enter the date ( in dd/mm/yyyy) format: 11/05/1995 Enter the Day on 1st January in this year: sunday 11/05/1995: Thursday Data Type Integer String Integer array String array Integer integer integer integer integer integer Purpose To store the number of days of all months. n<= 7 Test your program for the given data and some random data. You assume that the number of letter. n. Write a program to generate all possible anagrams of a word. Sample Data:Input: TO . i. Also output the total number of anagrams. To store the duplicate of day1. An anagram must be printed only once.e. To store the words To store the length and number of tokens To store the numerical day Temporary variable To store the numerical month To store the numerical year To alter value if it is leap year AIM: 15. You may output the anagrams in any order. To store first day of year. in the word will be 7 at most.

public class Anagrams { String str.readLine(). str=br.println("\nEnter the word:"). Step4-end process. System. int counter=0.and increment the value of counter by 1 each time. . } public void show(String s. show("".length()<=1) { counter++.*.Output: TO OT Total number of anagrams = 2 Input: TOP Output: TOP TPO OPT OTP PTO POT Total number of anagrams = 6 (ISC Practical 2005) ALGORITHM Step1-declare and initialize variables like str.io. Step3-print the number of anagrams.in)). BufferedReader br=new BufferedReader(new InputStreamReader(System.out. str). public void take()throws Exception { System. PROGRAM import java. counter Step2-find all the anagrams 1 by 1 .print them .println("Total number of anagrams ="+counter). String str) { if(str.out.

ngaes .str3 i OUTPUT String Integer string integer To store the input word To store the number of anagrams Temporary storage Loop variable Enter the word: nseag nseag .neags .gsnea . .seang .agsen .egnsa .aesgn .ganes . } } } public static void main(String args[])throws Exception { Anagrams ob=new Anagrams().gnsae .esgna .segna .System. Write a program which inputs a positive natural number N and prints the possible consecutive number combinations.geans .ganse .enags .aesng .gneas .nesga .engas .enasg .saeng . i + 1).ngase .nasge .substring(i.seagn .saegn . which when added give N.take().anegs .agnse . Test your program for the following data and some random data.neasg .gsane .gsaen .angse .esgan .sange .ansge . String str3 = str.substring(i + 1).aseng .negas .gsean .gesan .eagsn .gnsea .substring(0.ngesa .anesg .esagn .sgean .ngsea .naseg .egnas . } } str counter Str1.esang .naegs .snage . ob.nsgea .gsnae .sgnae .sgaen .nsage . } else { for(int i = 0.agens .ngeas .negsa .gesna .egans .sgena .asgen .senag .egsan .gnaes .nesag . i).eangs .saneg .sneag .gasen .asgne .easgn .segan .anges .anseg .nsgae .sngae .engsa . i++) { String str1 = str.asneg .out.egsna .nsaeg .naesg .genas . show(s + str1.gaens .print(s+str+" .asnge . i< str.aensg .gnase .geasn .sngea .snega .sgnea .agesn .ensga .esnga .sagne . String str2 = str.aengs .asegn .easng .Total number of anagrams =120 AIM: 16.length().egasn .nagse .gsena .senga .aegns .nsega .sagen .eagns .gasne .str2.gnesa .eansg . ").esnag .aegsn .agsne .gaesn .nages . str2 + str3).ensag .snaeg .agnes .sgane .ngsae .gensa .

Step2-Enter the number.i++) { sum=0. BufferedReader br=new BufferedReader(new InputStreamReader(System.out. (for e. Step5-end process.A positive natural number. i. Step4-pritn the numbers using loop with integer k. class NumberCombonation { int no. public void takeNumber()throws Exception { System. no=Integer.k.j<=no/2+1.io.println("Enter the number:").j.readLine()). for(j=i. PROGRAM import java. for(i=1.sum=0. Sample Data:Input N=9 Output 45 234 Input N = 15 Output 78 12345 456 (ISC Practical 2006) ALGORITHM Step1-declare variables like sum.parseInt(br. .i.in)). Step3-Find the numbers to be added. which add up to 27. j.*.j++) { sum=sum+j. k.g 27) can be represented as follows2+3+4+5+6+7 8+9+10 13+14 Every row represents a combination of consecutive natural numbers. no.i<=no/2+1.

} } no sum k i.j OUTPUT Enter the number: 152 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 integer Integer integer integer To store the input number. System. } if(j<=no/2+1) { for(k=i.out.k++) System. To store the sum of numbers To store the value each number to be added Loop variables .takeNumber().out.k<=j.if (sum==no) break. } } } public static void main(String args[])throws Exception { NumberCombonation obj=new NumberCombonation (). obj.println().print(" "+k).

A and B.m. B and C.AIM: 17. with no duplicates in either of them. Merge arrays A and B in to a single array C. Test your program for the given data and some random data. Display all the three arrays. Write a program that inputs the names of people in to different arrays. Step3-Sort the first and second array Step4-merge the 2 arrays by taking the smallest(Alphebetically) and placing first. Step3-enter the names for first and second array. B = 2 First array: (A) Suman Anil Second array: (B) Usha Sachin John Output: Stored Merged array: (C) Anil John Sachin Suman Usha Stored First array: (A) Anil Suman Stored second array: (B) John Sachin Usha (ISC Practical 2006) ALGORITHM Step1-declare and initialize variables like str1[]. N = 2 Enter number of names in Array A. A. stored alphabetically. Array A has N number of names while array B has M number of names.str3[].str2[].n. such that the resulting array is stored alphabetically. . Sample Data:Input: Enter number of names in Array A. Step2-Enter the number of names of the 2 arrays.

str1=new String[n]. display(). int n.readLine().println("Number of Names for second array:"). str2=new String[m]. } private void sort() { int flag.readLine()). m=Integer. n=Integer.sorted first array and second array.i++) { flag=0.Step5-print the merged array.out.i< n. for(j=0.trim(). int i.out.io.out. str1[j]=str1[j+1].j< n-i-1. } System. PROGRAM import java.readLine()).str3[]. str1[i]=br. for(i=0. class SortedNames { BufferedReader br=new BufferedReader(new InputStreamReader(System. } sort().out.out.*. System.j++) { if(str1[j]. String str1[].parseInt(br.parseInt(br.i++) { System. public void take ()throws Exception { System.trim().println("Name:").str2[].j.println("Names for 1st array:"). str2[i]=br.i< n.compareTo(str1[j+1]) >0) { s=str1[j]. str3=new String[n+m].i++) { System.readLine(). String s. System. .println("Number of Names for first array:"). Step5-end process.m.println("Names for 2nd array:").out.i< m. for(i=0.in)). merge().println("Name:"). for(i=0.

} } private void merge() { int x=0. i=0. . str2[j]=str2[j+1]. else str3[x++]=str2[j++].i< n. flag=1.j< m.compareTo(str2[j+1]) >0) { s=str2[j]. flag=1. while(i!=n && j!=m) { if(str1[i].j< m-i-1.j++) str3[x++]=str2[j].i++) { flag=0. } } private void display() { System. j=0.out. } } if(flag==0) break. } if(i==n) { for(. } for(i=0.j++) { if(str2[j].i< m. str2[j+1]=s.str1[j+1]=s. for(j=0.println("\nSorted Merged Names\n"). } else { for(.compareTo(str2[j])<=0) str3[x++]=str1[i++]. } } if(flag==0) break.i++) str3[x++]=str1[i].

for(i=0. } public static void main(String args[])throws Exception { SortedNames obj=new SortedNames().take(). obj.out. System.println("\nSecond array names\n").j. } } Str1[].println(str2[i]). for(i=0. System.println(" "). System.i< m+n.println("").i< n.out.out.str3 n.str2[].out. To store the number of digits of the 3 arrays.x OUTPUT String array Integer integer integer To store the three group of names. To check if the array is sorted.println(str1[i]). for(i=0.i++) System. System.i++) System. Loop variables Enter the number: Number of Names for first array: 3 Number of Names for second array: 2 Names for 1st array: Name: leon Name: nibuz Name: rotciv Names for 2nd array: Name: senga .i++) System.out.out.m flag i.println(str3[i]).println("\nFirst array names\n").i< m.out.

Name: esor Sorted Merged Names esor leon nibuz rotciv senga First array names leon nibuz rotciv Second array names esor senga .

The codes may or may not be in the consecutive series of alphabets.G. In case of no error. Develop a program to input a code and its length.I. Sample Data:Input: N=4 ABCE Output: Invalid! Only alternate letters permitted! Input: N=4 AcIK Output: Invalid! Only upper case letters permitted! .C. A new advanced Operating System. The security department has decided to have codes containing a jumbled combination of alternate uppercase letters of the alphabet starting from A upto K (namely among A. incorporating the latest hi-tech features has been designed by Opera Computer System. display the message “Valid!” Test your program for the following data and some random data.E.K).AIM: 18. The task of generating copy protection codes to prevent software piracy has been entrusted to the Security Department. At the first instance of an error display “Invalid!” stating the appropriate reason.

Input: N=4 AAKE Output: Invalid! Repetition of characters not permitted! Input: N=7 Output: Error! Length of string should not exceed 6 characters! Input: N=4 AEGIK Output: Invalid! String length not the same as specified! Input: N=3 ACE Output: Valid! Input: N=5 GEAIK Output: Valid! (ISC Practical 2006) ALGORITHM Step1-declare the variables like sentence. BufferedReader br=new BufferedReader(new InputStreamReader(System.print valid.n. Step2-enter the length.io.or if it exceeds 6 letters. Step6-check if it has alternate letters.in)).*. boolean bool. PROGRAM import java. class Sentence { String s1="ACEGIK". Step8-if it passes all given conditions. Step3-enter the code Step4-check if the input length is equal to the length of the string. Step9-end process. Step7-check if any letter is repeated. Step5-check if the code has only Upper case letters. .

charAt(i) >90) break.public void disp()throws Exception { int n. bool=checkChar(sentence). len=str. String sentence. if(!bool) return. } if(i==len) return true. System.out. System. bool=checkRepeat(sentence).println("Enter the code:"). if(!bool) return. System."). bool=checkSequence(sentence). if(!bool) return. else { . } private boolean checkChar(String str) { int i. } return b. } private boolean checkLength(String str.parseInt(br. sentence=br.length().readLine()).out.println("Error! Length of string should not exceed 6 characters!"). int n) { boolean b=true.out.readLine()...println("Enter the length:"). bool=checkLength(sentence.out.len. for (i=0. if(!bool) return. System. } else if(n>6) { b=false.println("Valid Input. System.println("Invalid! String length not the same as specified").out.i< len. n=Integer.length()) { b=false.n).i++) { if(str.charAt(i)< 65 || str. if(n!=str.

i++) { ch=str.println("Invalid! Only alternate letters are permitted."). else { System.indexOf(ch)< 0) break. } } private boolean checkSequence(String str) { int i.length().len.charAt(i)."). char ch.charAt(i).out. if(s1.j.System. return false.length()."). } } private boolean checkRepeat(String str) { int i. return false. return false. for (i=0.out. len=str.println("Invalid! Repetition of letters is not permitted. len=str. } if(i==len) return true. for (i=0.j< len.out. char ch.j++) { if(ch==str. } if(j!=len) break.println("Invalid! Only upper case characters are permitted. for(j=i+1. } if(i==len-1) return true.i< len-1.charAt(j)) break.len.i++) { ch=str.i< len. else { System. } } .

Loop variables OUTPUT Enter the code: BFJB Invalid! Only alternate letters are permitted. To store the length of the string. AIM: 19.. 135. The input contains two positive integers m and n. where m < n. 300 are not. 3121. For example 7. To store the size of input letters To check the given conditions.. You are to output the number of unique-digit integers in the .disp(). } } sentence n bool len i.public static void main(String args[])throws Exception { Sentence ob=new Sentence(). Assume m < 30000 and n <30000. A unique-digit integer is a positive integer (without leading zeros) with no duplicates digits.j String Integer boolean integer integer To store the input letters. write a program to determine how many unique-digit integers are there in the range between m and n (both inclusive) and output them. ob. Given two positive integers m and n. 214 are all unique-digit integers whereas 33. Enter the length: 3 Enter the code: ACE Valid Input.

c=0.m.k. 2547. 2541.io. 2513. index=0. 2539.in)). 2507. class Digit { int k. 103. Step3-Find the unique digits. 2546. 120.specified range along with their values in the format specified below: Sample Data:Input: m = 100 n = 120 Output: THE UNIQUE-DIGIT INTEGERS ARE: 102. 107. (ISC Practical 2007) ALGORITHM Step1-declare variables like arr[]. 2549. 2536. 2534. 2538. } Digit() { br=new BufferedReader(new InputStreamReader(System.c. PROGRAM import java. 2504.I. 2514. arr=new int[1000]. public static void main(String args[])throws IOException { Digit ob=new Digit(). 105. BufferedReader br. 2537. } public void take()throws IOException { . 2519. 2503.arr[]. 2540. Step4-print the digits. FREQUENCY OF UNIQUE-DIGIT INTEGERS IS : 9 Input: m = 2500 n = 2550 Output: THE UNIQUE-DIGIT INTEGERS ARE: 2501.i. 2531. 104. 2517. FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 28.c. 2510. 2509.show().take(). ob. 2518. 2530. 2543.*. 108.n.j.m.index. Step2-enter the lower and upper range.j. 2508. 2516. 2506. 2530. 106. 2548. 109.x. 2517.n. Step5-end process. ob.

i++) { index=0. for(k=0.i<=n.n c i.parseInt(br.readLine(). } if (j==0) { c++. } } System.parseInt(br. else arr[index++]=x. To store the range.out.out.j> 0.j=j/10) { x=j%10.print(" "+i). } if(k< index) break.integer.out.out. for(j=i. To store the number of unique digits Loop variables .while(true) { System. n=Integer.println("Enter the Lower range:"). for(i=m.k Integer array Integer integer Integer.trim()).println("\nFequency of unique digit integers is :"+ c). } } arr[] m.trim()).readLine(). System. } } void show () { System.integer To store the unique numbers.k++) { if (arr[k]==x) break.j.println("The unique digit integers are:").println("Enter the Upper range:"). System. m=Integer.out.k< index. if(m< n) break.

OUTPUT Enter the Lower range: 100 Enter the Upper range: 500 The unique digit integers are: 102 103 104 105 106 107 108 109 120 123 124 125 126 127 128 129 130 132 134 135 136 137 138 139 140 142 143 145 146 147 148 149 150 152 153 154 156 157 158 159 160 162 163 164 165 167 168 169 170 172 173 174 175 176 178 179 180 182 183 184 185 186 187 189 190 192 193 194 195 196 197 198 201 203 204 205 206 207 208 209 210 213 214 215 216 217 218 219 230 231 234 235 236 237 238 239 240 241 243 245 246 247 248 249 250 251 253 254 256 257 258 259 260 261 263 264 265 267 268 269 270 271 273 274 275 276 278 279 280 281 283 284 285 286 287 289 290 291 293 294 295 296 297 298 301 302 304 305 306 307 308 309 310 312 314 315 316 317 318 319 320 321 324 325 326 327 328 329 340 341 342 345 346 347 348 349 350 351 352 354 356 357 358 359 360 361 362 364 365 367 368 369 370 371 372 374 375 376 378 379 380 381 382 384 385 386 387 389 390 391 392 394 395 396 397 398 401 402 403 405 406 407 408 409 410 412 413 415 416 417 418 419 420 421 423 425 426 427 428 429 430 431 432 435 436 437 438 439 450 451 452 453 456 457 458 459 460 461 462 463 465 467 468 469 470 471 472 473 475 476 478 479 480 481 482 483 485 486 487 489 490 491 492 493 495 496 497 498 Fequency of unique digit integers is :288 .

vow. .io. int sen=1. class pro20 { public static void main(String args[])throws IOException { int i.sen. Step3-begin loop of I from0 to s. “ ! ” or “ ? ” followed by a space. Output: Sentence No. BEST OF LUCK. Step6-Repeat 4 and 5 for the next sentence. Write a program to: (i)Obtain the length of the sentence (measured in words) and the frequency of vowels in each sentence. A sentence is terminated by either “ . of words ---------------------------------------------------------1 2 1 2 5 3 3 8 4 4 3 3 (ISC Practical 2008) ALGORITHM Step1-initialize and declare variables like word.words andvowels.i. int vow=0. Assume that there will be a maximum of 10 sentences in a block.length-1 Step4-increment values of word and vowel if their respective character give the test Step5-print the number of sentence. int word=1. ” .*. Step6-End process PROGRAM import java. Step2-enter the sentences. Input a piece of text consisting of sentences. (ii)Generate the output as shown below using the given data Sample Data:Input: HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE.AIM: 20. of Vowels No.

and whatever you hit.charAt(i)==32) word++.out. String s=bf.call it the target. To store the number of vowels. To store the number of sentences.in)). sentence no:vowel no:words 1 10 7 2 3 2 3 7 4 4 5 4 . for(i=0.i++) { if(s. int len=s. sen++. else if((s. To store the input string OUTPUT Enter the sentences to be sure of hitting the target.charAt(i)=='.out.charAt(i)=='e')||(s.charAt(i)=='O')||(s.charAt(i)=='E')||(s. else if((s.charAt(i)=='i')||(s.charAt(i)=='o')||(s.')||(s. word=1.out.i<len.println(sen+"\t"+"\t"+vow+"\t"+"\t"+word).BufferedReader bf=new BufferedReader(new InputStreamReader(System.readLine().println("sentence no:vowel no:words"). } }}} VARIABLE DESCRIPTION Variable Name i word sen vow s Data Type integer Integer array Integer array Integer.charAt(i)=='I')| |(s. Integer string Purpose Loop variable To store the number of words.charAt(i)=='u')) vow++.charAt(i)=='!')||(s.length().charAt(i)=='?')) { System. System. System.charAt(i)=='U')||(s.shoot first.charAt(i)=='a')||(s.println("Enter the sentences").charAt(i)=='A')||(s.')||(s. vow=0.charAt(i)=='.

p.b.m.b[][]. Write a Java program to find the product of two matrices.j<n.i<m. p=Integer.readLine()). for(i=0.readLine()).parseInt(bf. System. BufferedReader bf=new BufferedReader(new InputStreamReader(System.k.out. n=Integer. System.readLine()).i.q. ALGORITHM Step1-declare variables like a.p. if(n==p) { if(m>20||n>20||p>20||q>20) { System.i++) { for(j=0.j.n.j.k.println("Enter the number of rows and columns for first and second matrices"). m=Integer.io.println("Enter the elements for first matrix").AIM: 3.*.exit(0).m.i.q.parseInt(bf. b=new int[p][q].parseInt(bf.out.in)). } a=new int[m][n]. q=Integer. System.out.parseInt(bf.readLine()). PROGRAM import java. Step 6-print the resultant array.j++) { . Step 2-Enter the size of the two arrays Step 3-check if the matrices are compatible for multiplication Step 4 Enter the elements of the 2 arrays Step 5-find the product by finding the sum of the products of the corresponding elements in the row of the first array and the column of the second.n. int c[][]=new int[m][q].println("Invalid input"). class multiple { public static void main(String args[])throws IOException { int a[][].

j<q.q a[][].p.k.integer. } } for(i=0.j++) { c[i][j]=0.parseInt(bf. } } System. } System.j<q.i<m. } } } System.i++) { for(j=0.readLine()). for(i=0.b[][] c[] i.println("Result is").k<n.j<q. for(i=0.j.integer.parseInt(bf. To store the two input arrays To store product Loop variables OUTPUT .out.out.k++) { c[i][j]+=a[i][k]*b[k][j].integer array Integer arrya Integer.integer.print(c[i][j]+" ").out.println().i++) { for(j=0. } } } }VARIABLE DESCRIPTION variable Name m.integer Integer array.i++) { for(j=0. for(k=0.a[i][j]=Integer.i<p.println("Enter the elements for second matrix").out.n.integer Purpose To size of the 2arrays.j++) { System.i<m. Data Type Integer.j++) { b[i][j]=Integer.readLine()).

Enter the number of rows and columns for first and second matrices 2 2 2 2 Enter the elements for first matrix 1 2 3 4 Enter the elements for second matrix 4 0 1 0 Result is 60 16 0 .

c. Arrange the sentence in alphabetical order of the words.in)). The sentence is terminated by either “. Each word must be in upper case.”.*. Step3-check if it is in uppercase. PROGRAM import java. OUTPUT: Length: 4 Rearranged Sentence: BE GOOD OTHERS TO (ISC Practical 2012) ALGORITHM Step1-declare the variables likei. OUTPUT: Length: 6 Rearranged Sentence: INVENTION IS MOTHER NECESSITY OF THE INPUT: BE GOOD TO OTHERS. import java. Test your program with the sample data and some random data: Sample Data:INPUT: NECESSITY IS THE MOTHER OF INVENTION. Perform the following tasks:   Obtain the length of the sentence (measured in words).util. String str. The words in the string are to be separated by a blank.io.words[]. .”!” or “?”. class Matrixmult { BufferedReader br=new BufferedReader(new InputStreamReader(System.AIM: 11. Step4-store the words in a string array Step5-sort the array in alphabetic order. Step6-print the words from the string array Step7-end process. Step2-Enter the sentence.x.j.*. Write a program to accept a sentence as input.

} } } System. } } if (flag==0) break.println("Enter the sentence:").out. str=br.readLine()..countTokens(). public void take()throws Exception { int flag. } System.length().println("\nRearranged Sentence:\n").j. StringTokenizer stk.compareTo(words[j])>0) { str=words[i].println("Length="+c).j++) { if(words[i]. for(i=0.c. System. . } stk=new StringTokenizer(str.isLowerCase(str. int i.out. while(stk.?!"). while(true) { flag=0. c=stk. words[i]=words[j].i< x-1.hasMoreElements()) { words[x++]=stk. for(i=0.String words[].nextToken().j< x.out.i++) { for(j=i+1. words[j]=str.i< str. x=0.charAt(i))) { flag=1. words=new String[c]." .i++) { if(Character. break.x.

i< c.out. integer Purpose To store the input sentence. ob.print(words[i]+" "). } } VARIABLE DESCRIPTION variable Name str Words[] i.for(i=0.x c Data Type string String array Integer.integer. OUTPUT Enter the sentence: AGGIE IS THE BESTEST CREATION OF GOD Length=7 Rearranged Sentence: AGGIE BESTEST CREATION GOD IS OF THE .integer. } public static void main(String args[]) throws Exception { Matrixmult ob=new Matrixmult().i++) System.take().j. Loop variables To count the number of tokens. To store the words.