Beruflich Dokumente
Kultur Dokumente
ACKNOWLEDGEMENT
I would like to thank my Computer Science Teacher , Mr. J.V. Nagendra Rao, who g
uided me in making this project by giving some valuable points. I would also lik
e to thank my parents who helped me in making this project more presentable.
TABLE OF CONTENTS
S.No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
29 30 PROGRAM TO create Pascal s triangle To display entered number in words To dis
play A.P. series and its sum To display calendar of any month of any year To cal
culate factorial using recursion To display Fibonacci series using recursion To
calculate GCD using recursion To display spiral matrix To display magical square
To search an array using Linear Search To search an array using Binary Search T
o sort an array using Selection sort To sort an array using Bubble sort To conve
rt a decimal no into it binary equivalent To display date from entered day no. T
o create a pattern from entered string To check if entered string is palindrome
or not To display a frequency of each character in entered string To find a word
in entered string To decode the entered string To display the entered string in
alphabetical order. To create a string and count number of vowels and consonant
s. To create a string and count number of words To create a string and replace a
ll vowels with * To create a double-dimensional array of 4*4 subscripts. To gene
rate sum of all elements of a double dimensional array of 5*5 subscripts To gene
rate product of two arrays of 5 subscripts as a third array To find sum of each
column of a double dimensional array To find sum of diagonal of a double dimensi
onal array of 4*4 subscripts To calculate the commission of a salesman PAGE No.
4 5 6 8 10 11 12 13 15 17 20 22 24 27 28 30 31 32 34 36 38 40 41 42 43 44 46 47
49 51
}
Output:
n=5 1 1 1 1 1 1 21 331 4641
PROGRAM 2 - To display entered number in words
Algorithm:
STEP STEP STEP STEP STEP STEP STEP 1234567START INPUT amt z=amt%10 , g=amt/10 IF
g!=1 THEN GOTO STEP 5 OTHERWISE GOTO STEP 6 PRINT x2[g-1]+" "+x1[z] PRINT x[amt
-9 END
SOLUTION:
import java.io.*; class eng { public static void main(String args[])throws IOExc
eption { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String x3; System.out.println("Enter any Number(less than 99)");
} APSeries(double a
{ return (a+(n-1)*d
showSeries(int n) {
System.out.print(nT
a=5 d=2 n=10 Series 5.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0 21.0 23.0 Sum : 140.0
PROGRAM 4 - To display calendar of any month of any year
Algorithm :
STEP 1 - START STEP 2 - INPUT int month,int year STEP 3 - int i,count=0,b,c,d=1
& String w="SMTWTFS" STEP 4 - IF (year%100==0 && year%400==0) || (year%100!=0 &&
year %4==0) STEP 5 - days[1]=29 STEP 6 - PRINT "================The Calendar of
"+month1[month-1]+" "+year+" is==================") STEP 7 - IF i=0 THEN GOTO S
TEP 8 STEP 8 - PRINT (i)+"\t" & " " STEP 9 - IF i=1 GOTO STEP 10 STEP 10 - IF (y
ear%100==0 && year%400==0) || (year%100!=0 && year %4==0)THEN GOTO STEP 11OTHERW
ISE GOTO STEP 12 STEP 11 - count+=2 STEP 12 - count+=1 STEP 13 - IF i=0 GOTO STE
P 14 STEP 14 - count+=days[i] , count+=1, count%=7 & b=7-count STEP 15 - IF b!=1
|| b!=7 GOTO STEP 16 STEP 16 - IF count>0 GOTO STEP 17,18 STEP 17 - PRINT ' '+"
\t") STEP 18 - count-STEP 19 - IF i=1 GOTO STEP 20 STEP 20 - IF b>0 && IF d<=day
s[month-1] GOTO STEP 21,22 STEP 21 - PRINT d+"\t" STEP 22 - d++ & b-STEP 23 - b=
7 STEP 24 - i++ & IF i<MONTH GOTO STEP14 STEP 25 - PRINT " " STEP 26 - END
SOLUTION:
class calendar { public void dee(int month,int year) { int i,count=0,b,c,d=1; St
ring w="SMTWTFS"; int days[]={31,28,31,30,31,30,31,31,30,31,30,31}; String month
1[]={"January","February","March","April","May","June","July", "August","Septemb
er","October","November","December"} ; If((year%100==0 && year%400==0) || (year%
100!=0 && year%4==0)) days[1]=29; System.out.println("================The Calend
ar of "+month1[month-1]+" "+year+" is=================="); for(i=0;i<w.length();
i++) System.out.print(w.charAt(i)+"\t"); System.out.println(" "); for(i=1;i<year
;i++) if((year%100==0 && year%400==0) || (year%100!=0 && year %4==0)) count+=2;
else count+=1; for(i=0;i<month;i++) count+=days[i]; count+=1; count%=7; b=7-coun
t; if(b!=1 || b!=7) while(count>0) { System.out.print(' '+"\t"); count--; } for(
i=1;i<7;i++) { while(b>0 && d<=days[month-1]) { System.out.print(d+"\t"); d++; b
--;
5 21 20 19 18 17 22 7 6 5 16 23 8 1 4 15 24 9 2 3 14 25 10 11 12 13
PROGRAM 9 - To display magical square
Algorithm:
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP
STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 21 22 START arr[][]=new int[n][n],c=n/2-1,r=1,num IF num=1;num<=n*n;num
++ GOTO STEP 4 r--,c++ IF r==-1 GOTO STEP 6 r=n-1 IF c>n-1 GOTO STEP 8 c=0 IF ar
r[r][c]!=0 GOTO STEP 10 r=r+2 & c-num++ & IF num<=n*n GOTO STEP 4 arr[r][c]=num
IF r==0&&c==0 GOTO STEP 14 r=n-1, c=1 & arr[r][c]=++num IF c==n-1&&r==0 GOTO STE
P 16 arr[++r][c]=++num PRINT () IFr=0 GOTO STEP 19 IF c=0 GOT STEP 20 PRINT arr[
r][c]+" " & () c++ & IF c<n GOTO STEP 20 r++ & r<n GOTO STEP 19 END
SOLUTION:
Output :
enter the dimension of magical square= 5 17 23 4 10 11 24 1 8 15 5 7 14 16 6 13
20 22 12 19 21 3 18 25 2 9
PROGRAM 10 - To search an array using Linear Search
Algorithm:
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 10 11 S
TART INPUT a[] FROM i=0 to i<n REPEAT STEP 4 PRINT a[i]+" " flag=-1 FROM i=0 to
i<n REPEAT STEP 7 IF (a[i] == v) THEN flag =i IF (flag=-1) THEN GOTO STEP 9 OTHE
RWISE GOTO STEP 10 PRINT
not found
PRINT v+" found at position - "+flag END
SOLUTION:
import java.io.*; class linear_search { int n,i; int a[] = new int[100]; static
BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); public
linear_search(int nn) {
} }
Output :
enter elements 5 3 8 4 1 6 4 7 9 5 5384164795 enter no. to be searched 1 1 found
at position - 4
PROGRAM 11 - To search an array using Binary Search
Algorithm:
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8
9 10 11 12 13 START INPUT a[] FROM i=0 to i<n REPEAT STEP 4 PRINT a[i]+" " flag
=-1 , l=0, u=n-1 IF(l<=u && flag=-1) REPEAT STEP 7 AND Step 8 m = (l+u)/2 IF (a[
m] == v) THEN flag =m OTHERWISE GOTO STEP 9 IF (a[m] < v) THEN l = m+1 OTHERWISE
u =m-1 - IF (flag=-1) THEN GOTO STEP 11 OTHERWISE GOTO STEP 12 - PRINT
not found
RINT v+" found at position - "+flag - END
- P
STEP 11 - END SOLUTION: import java.io.*; class binary_search { int n,i; int a[]
= new int[100]; static BufferedReader br =new BufferedReader(new InputStreamRea
der(System.in)); public binary_search(int nn) { n=nn; } public void input() thro
ws IOException { System.out.println("enter elements"); for(i=0;i<n;i++) { a[i] =
Integer.parseInt(br.readLine()); } } public void display() { System.out.println
(); for(i=0;i<n;i++) { System.out.print(a[i]+" "); } } public void search(int v)
{ int l=0; int u = n-1; int m; int flag=-1; while( l<=u && flag == -1) { m = (l
+u)/2; if(a[m] == v) flag = m;
1 1 found at position - 4
PROGRAM 12 - To sort an array using Selection sort
Algorithm:
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 10 11 START - INPUT a[] - FROM i=0 to i<n REPEAT STEP 4 - PRINT a[i]+" " - flag=-1 FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 11 - min =i - FROM j=i+1 to j<n REPEAT S
TEP 8 - IF(a[j]<a[min]) then min =j - IF (min!=i) GOTO STEP 11 - temp = a[i], a[
i] =a[min], a[min] = temp
SOLUTION:
import java.io.*; class selection_sort { int n,i; int a[] = new int[100]; public
selection_sort(int nn) { n=nn; } public void input() throws IOException { Buffe
redReader br =new BufferedReader(new InputStreamReader(System.in)); System.out.p
rintln("enter elements"); for(i=0;i<n;i++) { a[i] = Integer.parseInt(br.readLine
()); }
}
Output:
enter elements 4 6 1 2 9 Before sorting 46129 After sorting 12469
PROGRAM 13 - To sort an array using Bubble Sort
Algorithm:
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 10 - START INPUT a[] - FROM i=0 to i<n REPEAT STEP 4 - PRINT a[i]+" " - flag=-1 - FROM i=0
to i<n-1 REPEAT STEP 7 to STEP 9 - FROM j=i+1 to j<n REPEAT STEP 8 - IF(a[j] >
a[j+1]) THEN GOTO STEP 9 - temp = a[i], a[i] =a[min], a[min] = temp - END
SOLUTION:
import java.io.*; class bubble_sort { int n,i; int a[] = new int[100]; public bu
bble_sort(int nn) { n=nn;
import java.io.*; class dec_bin { int n,i; int a[] = new int[100]; static Buffer
edReader br =new BufferedReader(new InputStreamReader(System.in)); public dec_bi
n(int nn) { n=nn; } public void dectobin(int no) { int c = 0; int temp = no; whi
le(temp != 0) { a[c++] = temp % 2; temp = temp / 2; } System.out.println("Binary
eq. of "+no+" = "); for( i = c-1 ; i>=0 ; i--) System.out.print( a[ i ] ); } pu
blic static void main(String args[]) throws IOException { dec_bin obj = new dec_
bin(30); System.out.println("enter decimal no -"); int no = Integer.parseInt(br.
readLine()); obj.dectobin(no); } }
Output :
enter decimal no 56
Output:
enter the string = india iii nnn india iii aaa
PROGRAM 17 - To check if entered string is palindrome or not
Algorithm :
STEP STEP STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 START INPUT strin
g s StringBuffer sb = s sb.reverse String rev = sb IF rev = s GOTO STEP 7 OTHERW
ISE GOTO STEP 8 PRINT " Palindrome" PRINT " Not Palindrome" END
Solution:
import java.io.*; class palindrome {
ws IOException { BufferedReader br =
stem.in)); System.out.println("enter
ringBuffer sb = new StringBuffer(s);
Solution :
import java.io.*; class frequency { private int i,a1,l,p,j,freq; public frequenc
y() { p=0; freq=0;// initialise instance variables } public void count(String st
r) { int ii; l=str.length(); System.out.print(str); for(i=0;i<l;i++) { char a=st
r.charAt(i); for(ii=0;ii<l;ii++) { char b = str.charAt(ii); if (a==b) freq=freq+
1; } System.out.println(a+" occurs "+freq+" times"); freq=0; } } public static v
oid main(String args[]) throws IOException { BufferedReader br =new BufferedRead
er(new InputStreamReader(System.in)); System.out.println("enter string"); String
str = br.readLine(); frequency x = new frequency(); x.count(str); } }
Output:
enter string school s occurs 1 times c occurs 1 times h occurs 1 times o occurs
2 times o occurs 2 times l occurs 1 times
PROGRAM 19 - To find a word in entered string
Algorithm :
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 10
11 12 START INPUT string s StringTokenizer st = s l =str.length() INPUT look fl
ag = -1 IF (st.hasMoreElements()) REPEAT STEP 8 IF (look.equals(st.nextElement()
)) THEN flag =1 IF flag = - 1 GOTO STEP 10 OTHERWISE STEP 11 PRINT "word not fou
nd" PRINT "word found" END
Solution:
import java.util.StringTokenizer; import java.io.*; public class word_search {
Algorithm :
STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP STEP
STEP STEP STEP STEP STEP 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 S
TART INPUT name, n l=name.length() PRINT original string is "+name IF i=0 THEN G
OTO STEP 6 char c1=name.charAt(i) c=(int)c1 IF n>0 THEN GOTO STEP 9 THERWISE GOT
O STEP 12 IF (c+n)<=90 THEN GOTO STEP 10 OTHERWISE GOTO STEP 11 PRINT (char)(c+n
) c=c+n;c=c%10,c=65+(c-1) & PRINT (char)(c) ELSE IF n<0 THEN GOTO STEP 13 OTHERW
ISE GOTO STEP 19 n1=Math.abs(n) IF (c-n1) >=65 THEN GOTO STEP 15 OTHERWISE GOTO
STEP 16 DISPLAY (char) (c-n1) IF c>65 THEN GOTO STEP 17 OTHERWISE GOTO STEP 18 c
=c-65, c=n1 & PRINT (char)(90-(c-1)) ELSE IF n==0 DISPLAY "no change "+name END
Solution :
class decode { public void compute(String name,int n) { int j,i,l,c=0,y,n1; l=na
me.length(); System.out.println("original string is "+name); for(i=0;i<l;i++) {
char c1=name.charAt(i); try { c=(int)c1 ; }
Output:
enter word window dinoww
PROGRAM 22 - To create a string and count number of vowels and consonants.
Algorithm :
STEP 1 - START STEP 2 - a = "Computer Applications" STEP 3 - z = a.length() STEP
4 - x= 0 , b= 0 STEP 5 - FROM y =0 to y<z REPEAT STEP 6 STEP 6 - IF (a.charAt(y
)=='a'||a.charAt(y)=='e'||a.charAt(y)=='i'|| a.charAt(y)=='o'|| a.charAt(y)=='u'
) THEN x =x +1 OTHERWISE b = b+1 STEP 7 - PRINT x STEP 8 - PRINT b STEP 9 - END
Solution:
class p42 { public static void main(String args[]) { String a="Computer Applicat
ions";//initialising string int z=a.length(),y,x=0,b=0; for(y=0;y<z;y++)//loop f
or counting number of vowels { if(a.charAt(y)=='a'||a.charAt(y)=='e'||a.charAt(y
)=='i'||a.charAt(y)=='o'|| a.charAt(y)=='u') x++; else b++; }
Output:
The string is -Computer Applications Number of words in string =2
PROGRAM 24 - To create a string and replace all vowels with *.
Algorithm :
STEP 1 - START STEP 2 - a = "Computer Applications" STEP 3 - x= 0 STEP 4 - FROM
z =0 to z<a.length() REPEAT STEP 5 STEP 5 - if(a.charAt(z)=='a'||a.charAt(z)=='e
'||a.charAt(z)=='i'|| a.charAt(z)=='o'|| a.charAt(z)=='u') THEN a.setCharAt(z,'*
') STEP 6 - PRINT "New String -"+a STEP 7 - END
Solution:
import java.io.*; class p48 { public static void main(String args[]) { StringBuf
fer a=new StringBuffer("Computer Applications"); System.out.println("Original St
ring -"+a); int z=0; for(z=0;z<a.length();z++)//loop for replacing vowels with "
*" { if(a.charAt(z)=='a'||a.charAt(z)=='e'||a.charAt(z)=='i'||a.charAt(z)=='o'||
a.charAt(z)=='u') a.setCharAt(z,'*'); } System.out.println("New String -"+a); }
}
Output:
Original String -Computer Applications
Output:
Enter the array 1 2 3 4 5 6 7 8 9 Array 123 456 789
PROGRAM 26 - To generate sum of all elements of a double dimensional array of 5*
5 subscripts
Algorithm :
STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 STEP10 START INPU
T a[] FROM x =0 to x<5 REPEAT FROM y =0 to y<5 REPEAT PRINT (a[x][y]+" " FROM x
=0 to x<5 REPEAT FROM y =0 to y<5 REPEAT Sum=Sum+a[x][y] PRINT Sum - END
STEP 4 STEP 5 STEP 7 STEP 8
Solution:
class p33 { public static void main(String args[])throws IOException { int a[][]
=new int[5][5]; BufferedReader aa=new BufferedReader(new InputStreamReader(Syste
m.in)); int x,y,z,Sum=0; System.out.println("Enter the array");
}
Output:
Product of two arrays is4 6 21 32 25
PROGRAM 28 - To find sum of each column of a double dimensional array.
Algorithm :
STEP 1 - START STEP 2 - INPUT a[] STEP 3 - FROM x =0 to x<4 REPEAT STEP 4 - FROM
y =0 to y<4 REPEAT STEP 5 - PRINT (a[x][y]+" " STEP 6 - FROM x =0 to x<4 REPEAT
STEP 7 - FROM y =0 to y<4 REPEAT STEP 8 - Sum=Sum+a[x][y] , STEP 9 - PRINT Sum
STEP 10 - Sum = 0 STEP11 - END
STEP 4 STEP 5 STEP 7 , STEP 9 and STEP 10 STEP 8
Solution:
class p39 { public static void main(String args[])throws IOException { int a[][]
=new int[4][4]; BufferedReader aa=new BufferedReader(new InputStreamReader(Syste
m.in)); int x,y,z,Sum=0; System.out.println("Enter the array");//reading array f
or(x=0;x<4;x++) { for(y=0;y<4;y++) { z=Integer.parseInt(aa.readLine()); a[x][y]=
z; } } System.out.println("Array -");//printing the array in matrix form