ISC Practical Project Document
ISC Practical Project Document
ISCCOMPUTER SCIENCE
ACKNOWLEDGEMENT
ALGORITHM
STEP 1 - START
STEP 2 - pas[0] = 1
STEP 3 - IF i=0 THEN GOTO STEP 4
STEP 4 - IF j=0 THEN GOTO STEP 5
STEP 5 - PRINT pas[j]+" "
STEP 6 - i++& IF i<n GO TO STEP 4
STEP 7 - j=0 & IF j<=i GO TO STEP 5
STEP 8 - IF j=i+1 THEN GO TO STEP 7
STEP 9 - pas[j]=pas[j]+pas[j-1]
STEP 10 - j--& IF j>0 GO TO STEP 9
STEP 11 – END
solution
import java.io.*;
class Pascal
{public void pascalw()throws IOException //pascalw() function
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter a no.”);
int n=Integer.parseInt(br.readLine()); //accepting value
int [ ] pas = new int [n+1];
pas[0] = 1;
for (int i=0; i<n; i++) //loop evaluating the elements
{for (int j=0; j<=i; ++j)
System.out.print(pas[j]+" "); //printing the Pascal Triangle elements
System.out.println( );
for (int j=i+1; j>0; j--)
pas[j]=pas[j]+pas[j-1];
}}}
output
Algorithm
STEP 1 - START
STEP 2 - INPUT amt
STEP 3 - z=amt%10 , g=amt/10
STEP 4 - IF g!=1 THEN GOTO STEP 5 OTHERWISE GOTO STEP 6
STEP 5 - PRINT x2[g-1]+" "+x1[z]
STEP 6 - PRINT x[amt-9]
STEP 7 – END
solution
import java.io.*;
class Num2Words
{public static void main(String args[])throws IOException //main function
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter any Number(less than 99)");
int amt=Integer.parseInt(br.readLine()); //accepting number
int z,g;
String x[]={“”,"Ten","Eleven","Twelve", "Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
String x1[]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
String x2[]={"","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
z=amt%10; //finding the number in words
g=amt/10;
if(g!=1)
System.out.println(x2[g-1]+" "+x1[z]);
else System.out.println(x[amt-9]);
}}
output
ALGORITHM
STEP 1 - START
STEP 2 - a = d = 0
STEP 3 - IMPORT a, d
STEP 4 - this.a = a & this.d = d
STEP 5 - IMPORT n
STEP 6 - RETURN (a+(n-1)*d)
STEP 7 - IMPORT n
STEP 8 - RETURN (n*(a+nTHTerm(n))/2)
STEP 9 - IMPORT n
STEP 10 - PRINT \n\tSeries\n\t"
STEP 11 - IF i=1;i<=n;i++ GOTO STEP 12
STEP 12 - PRINT nTHTerm(i)+" "
STEP 13 - i++ & IF i<=n GOTO STEP 12
STEP 14 - PRINT n\tSum : "+Sum(n)
STEP 15 – END
Output
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 STEP 8
STEP 8 - PRINT (i)+"\t" & " "
STEP 9 - IF i=1 GOTO STEP 10
STEP 10 - IF (year%100==0 && year%400==0) || (year%100!=0 && year%4==0)
THEN GOTO STEP 11OTHERWISE GOTO STEP 12
STEP 11 - count+=2
STEP 12 - count+=1
STEP 13 - IF i=0 GOTO STEP 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<=days[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
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT n
STEP 3 - IF(n<2) THEN return 1 OTHERWISE return (n * fact(n-1))
STEP 4 – END
Solution
import java.io.*;
class Factorial
{public static void main(Str
ing args[]) throws IOException //main function
{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter no =");
int n = Integer.parseInt(br.readLine()); //accepting no.
Factorial obj = new Factorial();
long f = obj.fact(n);
System.out.println("Factorial ="+f); //displaying factorial
}
public long fact(int n) //recursive fact()
{if(n<2)
return 1;
else return (n*fact(n-1));
}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT n
STEP 3 - IF(n<=1) THEN return 1 OTHERWISE return (fib(n-1) +fib(n-2))
STEP 4 – END
Output
import java.io.*;
class Fibonacci
{public static void main(String args[]) throws IOException //main function
{Fibonacci obj = new Fibonacci();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter no of term ="); //accepting no. of terms
int n = Integer.parseInt(br.readLine());
System.out.println();
for(int i=1;i<=n;i++) //Fibonacci element display loop
{int f = obj.fib(i);
System.out.print(f+" ");
}}
public int fib(int n) //Recursive function fib() for calculation of Fibonacci element
{if(n<=1)
return n;
else
return (fib(n-1) +fib(n-2));
}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT p,q
STEP 3 - IF(q=0) THEN return p OTHERWISE return calc(q,p%q)
STEP 4 – END
Output
import java.io.*;
class GCD
{public static void main(String args[]) throws IOException//main function
{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the numbers =");
int p = Integer.parseInt(br.readLine()); //accepting nos.
int q = Integer.parseInt(br.readLine());
GCD obj = new GCD();
int g = obj.calc(p,q);
System.out.println("GCD ="+g);
}
public int calc(int p,int q) //recursive function calculating GCD
{if(q==0)
return p;
else return calc(q,p%q);
}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[][]
STEP 3 - IF p!=(int)Math.pow(l,2) GOTO STEP 4
STEP 4 - IF co!=0 GOTO STEP 5
STEP 5 - re=1
STEP 6 - IF ri=1;ri<=k1-re;ri++ GOTO STEP 7
STEP 7 - p++,c++
STEP 8 - IF c==l GOTO STEP 9
STEP 9 - BREAK
STEP 10 - a[r][c]=p
STEP 11 - IF c==l GOTO STEP 12
STEP 12 - BREAK
STEP 13 - IF dw=1 GOTO STEP 14
STEP 14 - p++,r++,a[r][c]=p
STEP 15 - IF le=1 GOTO STEP 16
STEP 16 - p++,c--,a[r][c]=p
STEP 17 - IF up=1 GOTO STEP 18
STEP 18 - p++,r--,a[r][c]=p
STEP 19 - k1=k1+2, k2=k2+2 & co++
STEP 20 - up++ & IF up<=k2-1 GOTO STEP 18
STEP 21 - le++ & IF le<=k2-1 GOTO STEP 16
STEP 22 - dw++ & IF dw<=k1-1 GOTO STEP 14
STEP 23 - IF y=0 GOTO STEP 24
STEP 24 - IF yy=0 GOTO STEP 25
STEP 25 - PRINT "\t"+a[y][yy]) & ()
STEP 26 - yy++ & IF yy<l GOTO STEP 25
STEP 27 - y++ & IF y<l GOTO STEP 24
STEP 28 – END
Output
ALGORITHM
STEP 1 - START
STEP 2 - arr[][]=new int[n][n],c=n/2-1,r=1,num
STEP 3 - IF num=1;num<=n*n;num++ GOTO STEP 4
STEP 4 - r--,c++
STEP 5 - IF r==-1 GOTO STEP 6
STEP 6 - r=n-1
STEP 7 - IF c>n-1 GOTO STEP 8
STEP 8 - c=0
STEP 9 - IF arr[r][c]!=0 GOTO STEP 10
STEP 10 - r=r+2 & c--
STEP 11 - num++ & IF num<=n*n GOTO STEP 4
STEP 12 - arr[r][c]=num
STEP 13 - IF r==0&&c==0 GOTO STEP 14
STEP 14 - r=n-1, c=1 & arr[r][c]=++num
STEP 15 - IF c==n-1&&r==0 GOTO STEP 16
STEP 16 - arr[++r][c]=++num
STEP 17 - PRINT ()
STEP 18 - IFr=0 GOTO STEP 19
STEP 19 - IF c=0 GOT STEP 20
STEP 20 - PRINT arr[r][c]+" " & ()
STEP 21 - c++ & IF c<n GOTO STEP 20
STEP 21 - r++ & r<n GOTO STEP 19
STEP 22 – END
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n REPEAT STEP 7
STEP 7 - IF (a[i] == v) THEN flag =i
STEP 8 - IF (flag=-1) THEN GOTO STEP 9 OTHERWISE GOTO STEP 10
STEP 9 - PRINT “ not found”
STEP 10 - PRINT v+" found at position - "+flag
STEP 11 – END
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1 , l=0, u=n-1
STEP 6 - IF(l<=u && flag=-1) REPEAT STEP 7 AND Step 8
STEP 7 - m = (l+u)/2
STEP 8 - IF (a[m] == v) THEN flag =m OTHERWISE GOTO STEP 9
STEP 9 - IF (a[m] < v) THEN l = m+1 OTHERWISE u =m-1
STEP 10 - IF (flag=-1) THEN GOTO STEP 11 OTHERWISE GOTO STEP 12
STEP 11 - PRINT “ not found”
STEP 12 - PRINT v+" found at position - "+flag
STEP 13 - END
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 11
STEP 7 - min =i
STEP 8 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 9 - IF(a[j]<a[min]) then min =j
STEP 10 - IF (min!=i) GOTO STEP 11
STEP 11 - temp = a[i], a[i] =a[min], a[min] = temp
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 9
STEP 7 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 8 - IF(a[j] > a[j+1]) THEN GOTO STEP 9
STEP 9 - temp = a[i], a[i] =a[min], a[min] = temp
STEP 10 - END
Output
ALGORITHM
STEP 1 - START
STEP 2 - n = 30
STEP 3 - INPUT int no
STEP 4 - c =0 , temp = no
STEP 5 - IF (temp!=0) REPEAT STEP 6
STEP 6 - a[c++] = temp%2, temp = temp / 2
STEP 7 - FROM i=c-1 to i>0 REPEAT STEP 8
STEP 8 - PRINT a[i]
STEP 9 – END
Solution
import java.io.*;
class Dec2Bin
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
public Dec2Bin(int nn) //parameterized contructor
{n=nn;
}
public void dectobin(int no) //function converting decimalto binary number
{int c = 0;
int temp = no;
while(temp != 0)
{a[c++] = temp % 2;
temp = temp / 2;
}
System.out.println("Binary eq. of "+no+" = ");
for( i = c-1 ; i>=0 ; i--) //Displaying binary number
System.out.print( a[ i ] );
Variable description
No. Name Type Method Description
1 br BufferedReader
e BufferedReader object
2 n int - array length
3 i int - loop variable
4 a[] int[] - array storing binary no.
5 nn int Dec2Bin() parameter in constructor
6 no int main(), dectobin() input number
7 temp int dectobin() temporary storage
8 c int dectobin() counter
9 obj Dec2Bi n main() Dec2Bin object
Output
ALGORITHM
STEP 1 - START
STEP 2 - INITIALISE a[ ] , m[ ]
STEP 3 - INPUT n , yr
STEP 4 - IF ( yr%4=0) THEN a[1] = 29
STEP 5 - t =0 , s = 0
STEP 6 - IF ( t<n) REPEAT STEP 7
STEP 7 - t =t + a[s++]
STEP 8 - d = n + a[--s] - t
STEP 9 - IF ( d ==1|| d == 21 || d == 31 ) then PRINT d + "st" + m[s] + "
, "+yr
STEP 10 - IF ( d ==2|| d == 22 ) then PRINT d + "nd" + m[s] + " , "+yr
STEP 11 - IF ( d ==3|| d == 23 ) then PRINT d + "rd" + m[s] + " , "+yr
OTHERWISE GOTO STEP 12
STEP 12 - PRINT d + "th" + m[s] + " , "+yr
STEP 13 – END
Output
Solution
import java.io.*;
class Pattern
{public static void main (Str
ing args[]) throws IOException
{int i,sp,j,k,l;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the string ="); //accepting string
String s = br.readLine();
l=s.length();
/*printing the pattern*/
for(i=0;i<l;i++)
if(i==l/2)
System.out.println(s);
else {sp=Math.abs((l/2)-i);
for(j=sp;j<l/2;j++)
System.out.print(" ");
k=0;
while(k<3)
{System.out.print(s.charAt(i));
for(j=0;j<sp-1;j++)
System.out.print(" ");
k++;
}
System.out.println(" ");
}}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT string s
STEP 3 - StringBuffer sb = s
STEP 4 - sb.reverse
STEP 5 - String rev = sb
STEP 6 - IF rev = s GOTO STEP 7 OTHERWISE GOTO STEP 8
STEP 7 - PRINT " Palindrome"
STEP 8 - PRINT " Not Palindrome"
STEP 9 – END
Solution
import java.io.*;
class Palindrome
{public static void main(String args[]) throws IOException //main function
{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the string=");
String s = br.readLine(); //accepting the string
StringBuffer sb = new StringBuffer(s);
sb.reverse(); //reversing the string
String rev = new String(sb);
if(s.equalsIgnoreCase(rev)) //checking for palindrome
System.out.println("Palindrome " ); //displaying the result
else System.out.println("Not Palindrome " );
}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT str
STEP 3 - l=str.length()
STEP 4 - PRINT str
STEP 5 - IF i=0 THEN GOTO STEP 4 OTHERWISE GOTO STEP 22
STEP 6 - char a=str.charAt(i)
STEP 7 - IF ii=0 THEN GOTO STEP 4 OTHERWISE GOTO STEP 22
STEP 8 - char b = str.charAt(ii)
STEP 9 - IF a==b GOTO STEP 10
STEP 10 - freq=freq+1
STEP 11 - ii++ & IF ii<1 GOTO STEP 8
STEP 12 - i++ & IF i<1 GOTO STEP 6
STEP 13 - DISPLAY a+" occurs "+freq+" times"
STEP 14 – END
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT string s
STEP 3 - StringTokenizer st = s
STEP 4 - l =str.length()
STEP 5 - INPUT look
STEP 6 - flag = -1
STEP 7 - IF (st.hasMoreElements()) REPEAT STEP 8
STEP 8 - IF (look.equals(st.nextElement())) THEN flag =1
STEP 9 - IF flag = - 1 GOTO STEP 10 OTHERWISE STEP 11
STEP 10 - PRINT "word not found"
STEP 11 - PRINT "word found"
STEP 12 – END
Solution
import java.util.StringTokenizer;
import java.io.*;
public class WordSearch
{public static void main(String[] args) throws IOException //main function
{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the string=");
String s = br.readLine(); //accepting string
StringTokenizer st = new StringTokenizer(s," "); //StringTokenizer initialization
System.out.println("enter the word to be searched =");
String look = br.readLine();
int flag = -1;
while(st.hasMoreElements()) //searching for word
{if(look.equals(st.nextElement()))
flag =1;
Variable description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 s String main() input string
3 st StringTokenizer main() StringTokenizer object
4 look String main() word to be searched
5 flag int main() flag
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT name, n
STEP 3 - l=name.length()
STEP 4 - PRINT original string is "+name
STEP 5 - IF i=0 THEN GOTO STEP 6
STEP 6 - char c1=name.charAt(i)
STEP 7 - c=(int)c1
STEP 8 - IF n>0 THEN GOTO STEP 9 THERWISE GOTO STEP 12
STEP 9 - IF (c+n)<=90 THEN GOTO STEP 10 OTHERWISE GOTO STEP 11
STEP 10 - PRINT (char)(c+n)
STEP 11 - c=c+n;c=c%10,c=65+(c-1) & PRINT (char)(c)
STEP 12 - ELSE IF n<0 THEN GOTO STEP 13 OTHERWISE GOTO STEP 19
STEP 13 - n1=Math.abs(n)
STEP 14 - IF (c-n1) >=65 THEN GOTO STEP 15 OTHERWISE GOTO STEP 16
STEP 15 - DISPLAY (char) (c-n1)
STEP 16 - IF c>65 THEN GOTO STEP 17 OTHERWISE GOTO STEP 18
STEP 17 - c=c-65,
STEP 18 - c=n1 & PRINT (char)(90-(c-1))
STEP 19 - ELSE IF n==0
STEP 20 - DISPLAY "no change "+name
STEP 21 - END
Output
ALGORITHM
STEP 1 - START
STEP 2 - str = "" , l = 0
STEP 3 - INPUT string str
STEP 4 - l =str.length()
STEP 5 - FROM i=0 to i<l REPEAT STEP 6
STEP 6 - c[i] = str.charAt(i)
STEP 7 - FROM i=0 to i<l-1 REPEAT STEP 8
STEP 8 - FROM j=0 to i<l-1 REPEAT STEP 9
STEP 9 - temp =c[j], c[j] = c[j+1] , c[j+1] = temp
STEP 10 - FROM i=0 to i<l REPEAT STEP 11
STEP 11 - PRINT c[i]
STEP 12 – END
Output
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
import java.io.*;
class Vowels
{public static void main(String args[])throws IOException //main function
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string");
String a= br.readLine(); //Accepting string
int z=a.length(),y,x=0,b=0;
for(y=0;y<z;y++) //loop for 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++;
}
System.out.println("Number of vowels in string ="+x); //displaying result
System.out.println("Number of consonants in string ="+b);
}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - a = "Computer Applications"
STEP 3 - z = a.length()
STEP 4 - x= 0
STEP 5 - FROM y =0 to y<z REPEAT STEP 6
STEP 6 - IF (a.charAt(y)==' ' ) then x =x+1
STEP 7 - PRINT "Number of words in string ="+(x+1)
STEP 8 – END
Solution
import java.io.*;
class NoOfWords
{public static void main(Str
ing args[])throws IOException
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Sentence");
String a=br.readLine(); //accepting string
System.out.println("The string is -"+a);
int z=a.length(),y,x=0;
for(y=0;y<z;y++) //loop for counting number of spaces
{if(a.charAt(y)==' ')
x=x+1;
}System.out.println("Number of words in string ="+(x+1)); //displaying result
}}
Output
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 VowelReplace
{public static void main(String args[])throws IOException //main function
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter a String”);
StringBuffer a=new StringBuffer(br.readLine()); //accepting a string
System.out.println("Original String -"+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); //displaying the result
}}
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM x =0 to x<5 REPEAT STEP 4
STEP 4 - FROM y =0 to y<5 REPEAT STEP 5
STEP 5 - PRINT (a[x][y]+" "
STEP 6 - FROM x =0 to x<5 REPEAT STEP 7
STEP 7 - FROM y =0 to y<5 REPEAT STEP 8
STEP 8 - Sum=Sum+a[x][y]
STEP 9 - PRINT Sum
STEP10 – END
Solution
import java.io.*;
class MatrixSum
{public static void main(String args[])throws IOException //main function
{ int a[][]=new int[5][5];
BufferedReader aa=new BufferedReader(new InputStreamReader(System.in));
int x,y,z,Sum=0;
System.out.println("Enter the array");
for(x=0;x<5;x++) //loop for reading array
{for(y=0;y<5;y++)
{ z=Integer.parseInt(aa.readLine()); //accepting array element
Variable description
No. Name Type Method Description
1 aa BufferedReader main() BufferedReader object
2 a int[][] main() input array
3 x int main() loop variable
4 y int main() loop variable
5 z int main() input element
6 Sum main() main() Sum of all elements
Output
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM x =0 to x<4 REPEAT STEP 4
STEP 4 - FROM y =0 to y<4 REPEAT STEP 5
STEP 5 - PRINT (a[x][y]+" "
STEP 6 - FROM x =0 to x<4 REPEAT STEP 7 , STEP 9 and STEP 10
STEP 7 - FROM y =0 to y<4 REPEAT STEP 8
STEP 8 - Sum=Sum+a[x][y] ,
STEP 9 - PRINT Sum
STEP 10 - Sum = 0
STEP11 – END
Solution
import java.io.*;
class ColoumnSum
{public static void main(String args[])throws IOException //main function
{int a[][]=new int[4][4];
BufferedReader aa=new BufferedReader(new InputStreamReader(System.in));
int x,y,z,Sum=0;
System.out.println("Enter the array"); //reading array
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{z=Integer.parseInt(aa.readLine());
a[x][y]=z;
}}
Variable description
No. Name Type Method Description
1 aa BufferedReader main() BufferedReader object
2 a int[][] main() input array
3 x int main() loop variable
4 y int main() loop variable
5 z int main() input element
6 Sum int main() Sum of each couloumn
Output
ALGORITHM
STEP 1- START
STEP 2- INPUT a[]
STEP 3- FROM x =0 to x<4 REPEAT STEP 4
STEP 4- FROM y =0 to y<4 REPEAT STEP 5
STEP 5- PRINT (a[x][y]+" "
STEP 6- FROM x =0 to x<4 REPEAT STEP 7
STEP 7 - Sum=Sum+a[x][y] , y=y+1
STEP 9- PRINT Sum
STEP 10 - Sum = 0
STEP11- END
Solution
import java.io.*;
class DiagonalSum
{public static void main(String args[])throws IOException //main function
{int a[][]=new int[4][4];
BufferedReader aa=new BufferedReader(new InputStreamReader(System.in));
int x,y,z,Sum=0;
System.out.println("Enter the array");
for(x=0;x<4;x++) //Reading array
{for(y=0;y<4;y++)
{z=Integer.parseInt(aa.readLine());
a[x][y]=z;
}}
System.out.println("Array -");
Variable description
No. Name Type Method Description
1 aa Buffere dReader main() BufferedReader object
2 a int[][] main() input matrix
3 x int main() loop variable
4 y int main() loop variable
5 Sum int main() Sum of diagonals
6 z int main() input element
Output
Sales Commission
>=100000 25% of sales
80000-99999 22.5% of sales
60000-79999 20% of sales
40000-59999 15% of sales
<40000 12.5% of sales
ALGORITHM
STEP 1 - START
STEP 2 - INPUT sales
STEP 3 - IF (sales>=100000) THEN comm=0.25 *sales OTHERWISE GOTO STEP 4
STEP 4 - IF (sales>=80000) THEN comm=0.225*sales OTHERWISE GOTO STEP 5
STEP 5 - IF (sales>=60000) THEN comm=0.2 *sales OTHERWISE GOTO STEP 6
STEP 6 - IF (sales>=40000) THEN comm=0.15 *sales OTHERWISE GOTO STEP 7
STEP 7 - comm=0.125*sales
STEP 8 - PRINT "Commission of the employee="+comm
STEP 9 – END
Solution
import java.io.*;
class SalesComission
{public static void main(String args[])throws IOException //main function
{double sales,comm;
BufferedReader aa=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter sales”);
sales=Double.parseDouble(aa.readLine()); //reading sales from the keyboard
Variable description
No. Name Type Method Description
1 aa BufferedReader main() BufferedReader object
2 sales double main() sales
3 comm. double main() commision
Output
ALGORITHM
STEP 1 – START
STEP 2 – Enter number num
STEP 3 -- hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}
STEP 4 -- ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
STEP 5 -- unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
STEP 6 – Display hund[num/100] and ten[(num/10)%10] and unit[num%10]
STEP 7 – END
Solution
import java.io.*;
public class Dec2Roman
{public static void main() th rows IOException //main function
{DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter Number : ");
int num=Integer.parseInt(in.readLine()); //accepting decimal number
String hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String ten[]={"","X","XX","XXX"," XL","L","LX","LXX","LXXX","XC"};
String unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
/*Displaying equivalent roman number*/
System.out.println("Roman Equivalent= "+hund[num/100]+ten[(num/10)%10]+unit[num%10]);
}}
Output
ALGORITHM
STEP 1 – START
STEP 2 -- Input temperature ‘celcius’ in celcius
STEP 3 – far=1.8*celcius + 32
STEP 4 – Display far
STEP 5 -- END
Solution
import java.io.*;
class C2F
{ public static void main(String args[])throwsIOException //main function
{Temperature ob= new Temperature();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter temperature in Celsius"); //accepting temperature
double temp=ob.convert(Double.parseDouble(br.readLine()));
System.out.println("The temperature in fahrenheit is = "+temp);
}}
class Temperature extends C2F
{double convert(double celcius) //function to convert Celsius to fahrenheit
{double far=1.8*celcius+32.0;
return far;
}}
Output