0% found this document useful (0 votes)
12 views

Final Project File Class 12

Uploaded by

panwarlucky536
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Final Project File Class 12

Uploaded by

panwarlucky536
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 75

COMPUTER SCIENCE

PRACTICAL FILE

SESSION
2023-2024

Submitted to: Submitted by:


Mrs. Sakshi Bhardwaj
CERTIFICATE

This is to certify that has completed his project his


project work of course curriculum, prescribed by the ISC for the
years 2022-23 under the supervision of Mrs. Sakshi Bhardwaj.
His project work is record of his genuine work.

Signature of Signature of Signature of


Student Internal Examiner External Examiner
PROGRAM

Write a program in Java to enter a natural number. Display all the possible
combinations of consecutive natural numbers which adds up to give the sum equal to
the original number.

import java.util.*;

public class Combination

public static void main(String args[])

int i,j,k,n,sum;

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number to print the combination of consecutive numbers");

System.out.println("Enter the number");

n=sc.nextInt();

for(i=1;i<=n/2;i++)

sum=0;

for(j=i;j<=n/2;j++)

sum=sum+j;

if(sum==n)

break;

if(j<=n/2+1)

for(k=i;k<=j;k++)

System.out.println(k+"");

System.out.println();

}
}

}
PROGRAM

Happy number is a number in which the eventual sum of square of its digit is equal to
1.Write a program to check if a given number is a happy number or not. Specify the
method Number(int n) that accepts a number from the main method. It returns 1(one)
or 0(zero) accordingly.

import java.util.*;

public class Happy

public int Number(int n)

int p,s=0,d;

p=n;

while(p>9)

s=0;

while(p>0)

d=p%10;

s= s+d*d;

p=p/10;

p=s;

return(s);

public static void main(String args[])

Scanner sc= new Scanner(System.in);

int k,m;
System.out.println("Enter the number");

m=sc.nextInt();

Happy ob= new Happy();

k=ob.Number(m);

if(k==1)

System.out.println(m+"is a happy number");

else

System.out.println(m+"is not a happy number");

}
PROGRAM.

Write a program to accept a string and pass it to method void Replace (String wd).The
method further replaces each letter by the next letter in opposite case. The conversion
follows round robin system (i.e., ‘Z’ follows ‘a’ and ‘z’ follows ‘A’).

import java.util.*;

public class Conversion

void Replace(String wd)

int i,p,k;

char chr;

k=wd.length();

System.out.println("Circular conversion of word followed by the next character:");

for(i=0;i<k;i++)

chr=wd.charAt(i);

if(chr>='a'&&chr<='y')

p=(int)(chr-31);

chr=(char)(p);

else if(chr=='z')

p=(int)(chr-57);

chr=(char)(p);

else if(chr>='A'&&chr<='Y')

p=(int)(chr+33);
chr=(char)(p);

else if(chr=='Z')

p=(int)(chr+7);

chr=(char)(p);

System.out.print(chr);

public static void main(String args[])

String str;

Scanner sc=new Scanner(System.in);

System.out.println("Enter a word");

str=sc.next();

Conversion ob=new Conversion();

ob.Replace(str);

}
PROGRAM

Write a program to accept two words and check whether they are Anagram or not. The words
that are made with the combinations of the letters present in the original words are called
Anagram.

import java.util.*;

public class Anagram

public static void main(String args[])

int p1,p2,i,j,as1,as2,s1=0,s2=0;

String str1,str2,str3="",str4="";

char chr1,chr2;

Scanner sc= new Scanner(System.in);

System.out.println("Enter first word");

str1=sc.next();

str1=str1.toUpperCase();

System.out.println("Enter second word");

str2=sc.next();

str2=str2.toUpperCase();

p1=str1.length();

p2=str2.length();

if(p1==p2)

for(i=65;i<=90;i++)

for(j=0;j<p2;j++)

chr1=str1.charAt(j);

chr2=str2.charAt(j);
as1=(int)chr1;

as2=(int)chr2;

if(as1==i)

str3=str3+chr1;

s1=s1+as1;

if(as2==i)

str4=str4+chr2;

s2=s2+as2; } } }

if(str3.equals(str4)&&(s1==s2))

System.out.println(str1+"and"+str2+"are Anagram words");

else

System.out.println(str1+"and"+str2+"are not Anagram words");

else

System.out.println("Wrong Input!!Re-enter words for Anagram");

}
PROGRAM

Write a class sentence to store a sentence and another class Duplicate to replace the duplicate
characters.The details of the classes are given below.
Class Name : Sentence
Data members/Instance variables : to store a sentence in the string variable of
protected type.
Members functions/Methods
Sentence( ) : constructor to assign string variable
void Accept( ) : to accept a sentence in the variable str
void Display( ) : to display the sentence after performing the
task .
Class Name : Duplicate
Data members/Instance variables :
p : to store the length of sentence of str
Member functions/methods :
Void remove Duplicate( ) : to remove the duplicate characters of each
word in Sequence so that it should have only
one occurrence. The new sentence should
possess only one space

import java.util.*;

public class Sentence

protected String str;

Sentence()

str="";

void Accept()

Scanner sc=new Scanner(System.in);

System.out.println("Enter name with the duplicate letters");

str=sc.nextLine();

void Display()

System.out.println(str);
}// end of base class

// to perform task in derived class

int len;

void removeDuplicate()

str=str+"";

len=str.length();

char b,c;

char st[]=new char[len];

int i,p;

String mdstr="";

p=len;

for(i=0;i<p;i++)

c=str.charAt(i);

st[i]=c;

for(i=0;i<p-1;i++)

c=st[i];

b=st[i+1];

if(b==c)

continue;

else

mdstr=mdstr+c;

System.out.println("Original String:"+str);

System.out.println("Modified String:"+mdstr);
}

}//end of derived class


PROGRAM.

Caesar Cipher is an encryption technique which is implemented as ROT13(‘rotate by 13


places’). It is a simple letter substitution cipher that replaces a letter with the letter 13 places
after it in the alphabets, with the other character remaining unchanged. Write a program to
accept a plain text of length L, where L must be greater than 3 and less than 100. Encrpt the
text if valid as per the Ceaser Cipher.

import java.util.*;

public class CaesarCiphar

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter plain text");

String str=sc.nextLine();

int len=str.length();

if(len<=3||len>=100)

System.out.println("INVALID LENGTH");

return;

StringBuffer sb=new StringBuffer();

for(int i=0;i<len;i++)

char ch=str.charAt(i);

if((ch>='A'&&ch<='M')||(ch>='a'&&ch<='m'))

sb.append((char)(ch+13));

else if((ch>='N'&&ch<='Z')||(ch>='n'&&ch<='z'))

sb.append((char)(ch-13));
else

sb.append(ch);

String cipher=sb.toString();

System.out.println("The ciphher text is:");

System.out.println(cipher);

}
PROGRAM

A square matrix is said to be a magic square, if the sum of each row, each column and each
diagonal is same. Write a program to enter an integer number N. Create a magic square of size
N x N.. Finally, print the elements of the matrix as magic square.

import java.util.*;

public class Magic_Square

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int i,j,k,n,t;

System.out.println("Enter matrix dimension of a magic square");

System.out.println("Enter number of rows only of a magic square");

n=sc.nextInt();

int a[][]=new int[n][n];//initializing double dimensional array

for(i=0;i<n;i++)

for(j=0;j<n;j++)

a[i][j]=0;

if(n%2!=0)

i=0;j=n/2;k=1;

while(k<=n*n)

a[i][j]=k++;

i--;j++;

if(i<0 && j>n-1)

{
i=i+2;

j--;

if(i<0)

i=n-1;

if(j>n-1)

j=0;

if(a[i][j]>0)

i=i+2;

j--;

else

k=0;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

a[i][j]=++k;

j=n-1;

for(i=0;i<n/2;i++)

t=a[i][i];

a[i][i]=a[j][j];

a[j][j]=t;
t=a[i][j];

a[i][j]=a[j][i];

a[j][i]=t;

j--;

System.out.println("Magic square of size"+n+"x"+n+":");

for(i=0;i<n;i++)

for(j=0;j<n;j++)

System.out.print(a[i][j]+"\t");

System.out.println();

}
PROGRAM

Write a program to create a Double Dimensional Array of order[m]*[m](where m represents


the number of rows and columns) to store integer numbers. Now ,pass the array to a method
Diagonal() which calculates the sum of left and right diagonal elements. Finally, display the
elements of original matrix and also the sum of left and right diagonal elements .

import java.util.*;

public class Sum_diagonals

void Diagonal(int arr[][],int rc)

int i,j,k,ld=0,rd=0;

System.out.println("Elements of the matrix are:");

for(i=0;i<rc;i++)

for(j=0;j<rc;j++)

System.out.print(arr[i][j]+"");

System.out.println();

for(i=0;i<rc;i++)

ld=ld+arr[i][i];

System.out.println("The sum of the left diagonal elements="+ld);

k=rc-1;

for(i=0;i<rc;i++)

rd=rd+arr[i][k];

k=k-1;
}

System.out.println("The sum of the right diagonal elements="+rd);

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int i,j,rc;

System.out.println("Enter numbers of rows and columns of the of the matrix:");

rc=sc.nextInt();

int m[][]=new int[rc][rc];

System.out.println("Enter the numbers of the matrix:");

for(i=0;i<rc;i++)

for(j=0;j<rc;j++)

m[i][j]=sc.nextInt();

Sum_diagonals ob=new Sum_diagonals();

ob.Diagonal(m,rc);

}
PROGRAM

Write a program in Java to enter a natural number. Display all the possible
combinations of consecutive natural numbers which adds up to give the sum equal to
the original number.

import java.util.*;

public class Combination

public static void main(String args[])

int i,j,k,n,sum;

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number to print the combination of consecutive numbers");

System.out.println("Enter the number");

n=sc.nextInt();

for(i=1;i<=n/2;i++)

sum=0;

for(j=i;j<=n/2;j++)

sum=sum+j;

if(sum==n)

break;

if(j<=n/2+1)

for(k=i;k<=j;k++)

System.out.println(k+"");

System.out.println();

}
}

}
PROGRAM

Write a menu driven program to perform the given task as per the user’s choice :

(i) to enter a number containing 3 digits or more.

Arrange the digits of the entered number in ascending order and display the result.

(ii) a number is said to be a ‘Magic Number’, if eventual sum of the digits of the number is
equal to 1 , otherwise not . Enter a number and check whether it is a magic number or not.

import java.util.*;

public class Choice

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int i,j,p,r,ch,n;

System.out.println("Enter 1 to arrange the digits of a number in ascending order");

System.out.println("Enter 2 to check whether a number is magic or not");

System.out.println("Enter your choice");

ch=sc.nextInt();

switch(ch)

case 1:

System.out.println("Enter a number");

n=sc.nextInt();

System.out.println("The digits of the number in ascending order:");

for(i=0;i<10;i++)

p=n;

while(p!=0)

{
r=p%10;

if(r==i)

System.out.print(r+",");

p=p/10;

System.out.println();

break;

case 2:

int a ,b,c,s;

System.out.println("Enter a number");

n=sc.nextInt();

s=n;

while(s>9)

n=s;s=0;

while(n>10)

a=n/10;

b=a*10;

c=n-b;

s=s+c;

n=a;

if(s==1)
System.out.println("Magic Number");

else

System.out.println("Not a magic number");

break;

default:

System.out.println("It is a wrong choice!!!");

}
PROGRAM

Write a program to input a String and reverse it by using recursive function . Display the new
String formed after reversal.

import java.util.*;

public class Str_rev

public static String reverse(String s,int p,String rev)

if(p<0)

return(rev);

else

rev=rev+s.charAt(p);

return(reverse(s,p-1,rev));

} }

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter a sr=tring to be reversed");

String st=sc.nextLine();

String res=reverse(st,st.length()-1,"");

System.out.println("String after reversing the characters\t"+res);

}}
PROGRAM

Write a program ( Using Scanner Class ) to enter a token / word in a mixed case and display the
new token after deleting all the vowels. Finally arrange the new token in alphabetical order of
letters.

import java.util.*;

public class Dvowels

public static void main(String args[])

Scanner sc=new Scanner(System.in);

inti,j,p,q;

char ch,ch1;

String st,st2="",st3="";

System.out.println("Enter a word");

st=sc.next();

p=st.length();

for(i=0;i<p;i++)

ch=st.charAt(i);

if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='E'||ch=='I'||ch=='O'||ch=='U')

continue;

st2=st2+ch;

System.out.println("The new token formed after deleting the words:"+st2);

q=st2.length();

for(i=65;i<=90;i++)

for(j=0;j<q;j++)

{
ch1=st2.charAt(j);

if(ch1==(char)i||ch1==(char)(i+32))

st3=st3+ch1;

System.out.println("The new token formed after arranging in alphabetically order:"+st3);

}
PROGRAM

Write a program in java to accept a decimal number ( base 10 ) . Convert the decimal number to a
hexadecimal number and display the result.

import java.util.*;

public class DeciHexa

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int i=0,c=0,n,r;

int ar[]=new int[20];

System.out.println("Enter a decimal number");

n=sc.nextInt();

System.out.println("The HexaDecimal equivalent of Decimal Number:"+n);

while(n>0)

r=n%16;

ar[i]=r;

n=n/16;

i++;
c++;

for(i=c-1;i>=0;i--)

if((ar[i]>=10)&&(ar[i]<=15))

if(ar[i]==10)

System.out.println("A");

if(ar[i]==11)

System.out.println("B");

if(ar[i]==12)

System.out.println("C");

if(ar[i]==13)

System.out.println("D");

if(ar[i]==14)

System.out.println("E");

if(ar[i]==15)

System.out.println("F");

else

System.out.print(ar[i]);

System.out.println();

}
PROGRAM

Write a program in java to accept a string from the user. Count and display the number of uppercase
characters , the number of lowercase characters , and the number of vowels as per the User’s choice

( using switch case ).

( i ) To count the uppercase characters

( ii ) to count the lowercase characters

( iii ) to count the number of vowels

import java.util.*;

public class Count

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int i,p,up=0,low=0,v=0,ch;

String str;

char chr;

System.out.println("Enter a string");

str=sc.nextLine();

p=sc.nextInt();

System.out.println("Enter 1 to count uppercase characters");


System.out.println("Enter 2 to count lowercase characters");

System.out.println("Enter 3 to count vowels");

System.out.println("Enter your choice");

ch=sc.nextInt();

switch(ch)

case 1:

for(i=0;i<p;i++)

chr=(str.charAt(i));

if(Character.isUpperCase(chr))

up=up+1;

System.out.println("The number of uppercase characters="+up);

break;

case 2:

for(i=0;i<p;i++)

chr=(str.charAt(i));

if(Character.isLowerCase(chr))

low=low+1;

System.out.println("The number of lowercase characters="+low);

break;

case 3:

for(i=0;i<p;i++)

chr=(str.charAt(i));
if((chr=='A')||(chr=='E')||(chr=='I')||(chr=='O')||(chr=='U')||(chr=='a')||(chr=='e')||
(chr=='i')||(chr=='o')||(chr=='u'))

v=v+1;

System.out.println("The total no.of vowels="+v);

break;

default:

System.out.println("Wrong choice!!!");

}
PROGRAM

Using scanner class , write a program to enter a text line ending with a space and terminated with a
full stop ( . ) . Display the frequency of the word ‘The / the’ in the given text line. However the word
‘The / the’ should not be a substring of another word .

import java.util.*;
public class Frequency
{
public static void main(String args[])

Scanner sc=new Scanner(System.in);

int c=0;

String st;

System.out.println("Enter line ending with space and terminated with(.):");

while(true)

st=sc.next();

if(st.equals("The")||st.equals("the"))

c=c+1;

if(st.equals("."))

break;

} System.out.println("Frequency of token 'The/the'="+c);

}}
PROGRAM

A class Myarray contains an array of n integers (n<=100) that are already arranged in ascending
order. The subscripts of the array elements vary from 0 to n-1. Some of the members functions/
methods of Myarray are given below:
Class Name : Myarray
Data members/Instance varibles :
arr : an array of n integers.
n : size of the array .
Member functions/ methods :
Myarray() : Constructor to initialize 0 in each memory location
of
the array arr [].
voidreadarray( ) : read n integers that are arranged in ascending order.
voiddisplayarray( ) : displays n integers.
intbinarysearch(int value) : searches for the ‘value’ in the array using the binary
search technique. It returns the subscript of the array
Element if the value is found , otherwise it
Returns – 999.
Specify the class Myarray giving the details of the void displayarray( ) and intbinarysearch( int value)
only . You may assume that the other functions/methods are written for you . You do not need to write
the main function.

Import java.util.*;

public class Myarray

intar[]=new int[100];

intn,i;

Myarray(int nm)

n=nm;

for(i=0;i<100;i++)
ar[i]=0;

voidreadarray()

Scanner sc=new Scanner(System.in);

for(i=0;i<n;i++)

System.out.println("Enter a number");

ar[i]=sc.nextInt();

voiddisplayarray()

System.out.println("Elements in the array are:");

for(i=0;i<n;i++)

System.out.print(ar[i]+"");

System.out.println();

intbinary_search(int value)

intlb,ub,mid,found=0,ret;

lb=0;

ub=n-1;

mid=0;

while(found==0&&lb<=ub)

mid=(lb+ub)/2;

if(value<ar[mid])
ub=mid-1;

if(value>ar[mid])

lb=mid+1;

if(value==ar[mid])

found=1;

if(found==1)

ret=value;

else

ret=-999;

return(ret);

}
PROGRAM

Write a program to input ‘n’ integer numbers ( positive or negative ) in a Single Dimensional Array
(SDA ). Pass the array to a function sort ( int arr[ ] ) . Arrange all the numbers in ascending order and
display the result.

import java.util.*;

public class Sorting

void sort(int arr[])

int p=arr.length;

int i,j,t;

for(i=0;i<(p-1);i++)

for(j=i+1;j<p;j++)

if(arr[i]>arr[j])

t=arr[i];

arr[i]=arr[j];

arr[j]=t;

System.out.println("The numbers arranged in ascending order are:");

for(i=0;i<p;i++)

System.out.println(arr[i]);

}
public static void main(String args[])

Scanner sc=new Scanner(System.in);

Sorting ob=new Sorting();

int n,i;

int m[]=new int[100];

System.out.println("Enter number of elements to store:");

n=sc.nextInt();

for(i=0;i<n;i++)

System.out.print("Enter integer number in the cell"+(i+1)+":");

m[i]=sc.nextInt();

ob.sort(m,n);

}
PROGRAM

Design a program which accepts your date of birth in mm ddyyyy format . Check whether the date is
a valid date or not . If it is valid , display “ Valid Data” . It also computes and displays the day number
of the year for the date of birth. If it is invalid , display “Invalid Data” and terminate the program.

importjava.util.*;

public class Validation

public static void main(String args[])

Scanner sc=new Scanner(System.in);

inti,d,m,y,f=1,s=0;

int nod[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

System.out.println("Enter your date of birth in dd,mm,yyyy format");

d=sc.nextInt();

m=sc.nextInt();

y=sc.nextInt();

if(m>12)

f=0;

if(m==2)

if(y%4==0)

if(d>29)

f=0;

else

if(d>28)

f=0;

if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)

{
if(d>31)

f=0;

else

if(d>30)

f=0;

if(f==1)

System.out.println("Date is valid");

i=1;

while(i<m)

s=s+nod[i];

i++;

s=s+d;

System.out.println("Day number of the year:"+s);

else

System.out.println("Invalid date");

}}
PROGRAM

A Gold Batch Number is a positiveeven integer that can be expressed as the sum of two primes.
Note : All integer number s greater than 4 are goldbatch numbers.

import java.util.*;

public class GoldbachNumber

public static boolean isPrime(int num)

int c=0;

for(int i=1;i<=num;i++)

if(num%i==0)

c++;

return c==2;

public static void main(String rgs[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the value of N:");

int n= sc.nextInt();

if(n<=9||n>=50)

System.out.println("Invalid input.Number out of range.");

return;

if(n%2!=0)
{

System.out.println("Invalid input.Number is odd.");

return;

System.out.println("Prime pairs are:");

int a=3;

int b=0;

while(a<=n/2)

b=n-a;

if(isPrime(a)&&isPrime(b))

System.out.println(a+","+b);

a+=2;

PROGRAM
Checks whether the ISBN code is valid or not.
Sample Input :
0201103311
Sample Output :
Sum= 55
LEAVES NO REMAINDER – VALID ISBN CODE

import java.util.*;
public class ISBN

public static void main()

Scanner sc=new Scanner(System.in);

String s;

int sum=0,l,i;

char c;

System.out.println("Enter the ISBN number:");

s=sc.nextLine();

l=s.length();

if(l==10)

for(i=10;i>1;i--)

c=s.charAt(10-i);

if((c=='x'||c=='X'))

sum=sum+(10*i);

else

sum=sum+(Integer.parseInt(c+"")*i);

}
}

System.out.println("SUM="+sum);

if(sum%11==0)

System.out.println("LEAVES NO REMAINDER-VALID ISBN CODE");

System.out.println("LEAVES REMAINDER=INVALID ISBN CODE");

else

System.out.println("INVALID INPUT");

PROGRAM

A Company manufactures packing cartons in four sizes,sizes,i.e.cartons to accommodate 6


boxes,12 boxes,24 boxes and 48 boxes.Design a program to accept the number of boxes to be
packed (N) by the user (maximum upto 1000 boxes)and display the break up of the cartons used
in descending order of capacity (i.e. preference should be given to the highest capacity
available , and if boxes left are less than 6, an extra carton 6 should be used.

import java.util.*;

public class CartonBoxes

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.print("Enter number of boxes(N):");

int n=sc.nextInt();

if(n<1||n>1000)

System.out.println("INVALID INPUT");

return;

int cartonSizes[]={48,24,12,6};

int total=0;

int t=n;

for(int i=0;i<cartonSizes.length;i++)

int cartonCount=t/cartonSizes[i];

t=t%cartonSizes[i];

total+=cartonCount;

if(cartonCount!=0)

System.out.println(cartonSizes[i]+"*"+cartonCount+"="+(cartonSizes[i]*cartonCount));

}}

if(t!=0){

System.out.println("Remaining boxes="+t+"*1+"+t);
total++;

else{

System.out.println("Remaining boxes=0");

System.out.println("Total number of boxes="+n);

System.out.println("Total number of cartons+"+total);

PROGRAM

Write a program to input a String and reverse the original String by using recursive function.
Display the new String.

import java.util.*;

class strrev
{

public static String reverse(String s,int I,String rev)

if(I<0)

return(rev);

else

rev=rev+s.charAt(I);

return(reverse(s,I-1,rev));

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter a string to be reversed");

String st=sc.next();

String res=reverse(st,st.length()-1,"");

System.out.println("String after reversing the character\t"+res);

}
PROGRAM
A bank intends to design a program to display the denominations of an input amount , up to 5 digits.
The available denomination with the bank are of rupees 2000,500,200,100,50,20,10 and 1.

Design a program to accept the amount from the user and display the break-up in descending order of
denominations (i.e.preference should be given to the highest denomination available ) along with the
total number of votes.

[Note : Only the denomination used should be displayed ].

Also print the amount in words according to the digits.

import java.util.*;

public class Denominations

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.print("Enter the amount");

int amt=sc.nextInt();

if(amt>99999)

System.out.println("Invalid Amount");

return;

String amtlnWords=getAmtlnWords(amt);

System.out.println("amtln words");

System.out.println("Denomionations");

int notes[]={2000,500,200,100,50,20,10,1};

int t=amt;

for(int i=0;i<notes.length;i++)

{
int c=t/notes[i];

if(c!=0)

System.out.println(notes[i]+"\t*\t"+c+"\t=\t"+(c*notes[i]));

t=t%notes[i];

public static String getAmtlnWords(int amt)

StringBuffer sb=new StringBuffer();

while(amt!=0)

int d=amt%10;

amt/=10;

switch(d)

case 0:

sb.insert(0,"Zero");

break;

case 1:

sb.insert(0,"One");

break;

case 2:

sb.insert(0,"Two");

break;

case 3:

sb.insert(0,"Three");

break;

case 4:
sb.insert(0,"Four");

break;

case 5:

sb.insert(0,"Five");

break;

case 6:

sb.insert(0,"Six");

break;

case 7:

sb.insert(0,"Seven");

break;

case 8:

sb.insert(0,"Eight");

break;

case 9:

sb.insert(0,"Nine");

break;

default:

System.out.println("Invaild digit");

return sb.toString();

}
PROGRAM

Write a program to declare a matrix num[][]of order(M x N) where ‘M’ is the number of rows and ‘N’
is the number of columns such that the values of both ‘M’ and ‘N’ should be greater than 2 and less
than 10. Allow the user to input positive integers into this matrix. Perform following task on the
matrix:

(i) Display the original matrix.

(ii) Sort each row of the matrix in ascending order using any standard sorting technique.

(iii) Display the changed matrix after sorting each row.

import java.util.*;

public class MatrixSort

{
public static void main()

Scanner sc=new Scanner(System.in);

int m,n,j,k,i,t;

System.out.println("Enter number of rows and columns");

m=sc.nextInt();

n=sc.nextInt();

if(m<=2&&m>=20||n<=2&&n>=20)

System.out.println("Matrix size out of range");

else

int num[][]=new int[m][n];

System.out.println("Enter matrix element");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

num[i][j]=sc.nextInt();

System.out.println("Original Matrix");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

System.out.println(num[i][j]+"\t");

System.out.println();

for(i=0;i<m;i++)

for(j=0;j<n;j++)
{

for(k=0;k<(n-1-j);k++)

if(num[i][k]>num[i][k+1])

t=num[i][k];

num[i][k]=num[i][k+1];

num[i][k+1]=t;

System.out.println("Matrix after sorting rows");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

System.out.println(num[i][j]+"\t");

System.out.println();

}
PROGRAM

Write a program by using class Employee to store the details of an employee and another Class
Overtime to Calculate the amount paid for working more than the normal working Hours.The details
of the classes are given below:
Class name : Employee
Data members/ instance variable :
Empc: to store employee code
Bpay: to store basic salary n double type
Member fuctions/ methods:
Employee() : constructor to assign 0 to empc and Bpay
Employee(int c, double b): constructor to assign ‘c’ to empc and b to Bpay
Void Dislplay() : to display empc and Bpay
Class name : overtime
Data members / instance variables:
Nd: to staore number(int) ofextra hours worked
Member function/methods:
Overtime(int n, float r)
Double calculate()
Void Shoe()
Use concept of inheritance.

import java.util.*;

public class Employee

int impc;

double bpay;

Employee()

impc=0;

bpay=0;

void Employee(int c,double b)

impc=c;

bpay=b;

void display()

System.out.println("Employee code="+impc);

System.out.println("Basic pay=rs"+bpay);

class overtime extends Employee


{

int nd;

double rate;

overtime(int n,double r)

nd=n;

rate=r;

double calculate()

double ts;

ts=bpay+(nd*rate);

return(ts);

void show()

display();

double x=calculate();

System.out.println("Number of days worked"+nd);

System.out.println("Amount paid for extra hours"+(nd*rate));

System.out.println("Salary"+x);

}
PROGRAM

A class called evenseries has been definedto find the smallest value of integer , n such that :

4/2!+ 8/3! +16/4!+-----------------+2n/n!>=s where 2.0 <s <7.0

import java.util.*;

class EvenSeries

int n,i;

double s;

EvenSeries()

s=0;

n=0;

void accept()

Scanner sc=new Scanner(System.in);

System.out.println("Enter the value of n");

n=sc.nextInt();

long fact(long g)

long f=1;

int j;

for(j=1;j<=g;j++)

f=f*j;

return(f);

}
void display()

double p,k;

for(i=2;i<=n;i++)

p=Math.pow(2,i);

k=fact(i);

s=s+(double)p/k;

if (s>2.0&&s<7.0)

break;

System.out.println("The least value of n="+i);

System.out.println("Sum of the Even Series="+s);

}//end of i loop

}//end of display()
PROGRAM

The Mobius function M (N) for a natural number N is defined as:

M (N) = 1: IF N =1= 0: IF any prime factor of p distinct prime factors.Write a program to input a
positive natural number N and output M (N). The program should continue till the user wants.Check
your program for N=78,N=34,N=12,N=17,N=666,N=327,N=29 and so on.

import java.util.*;

public class Mobius_function

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int j,p,n,c;

c=0;

double m;

m=0.0;

System.out.println("Enter a number");

n=sc.nextInt();

if(n==1)

System.exit(1);

j=2;p=0;

while(j<=n)

if(n%j==0)

c++;

n=n/j;

p++;
if(p>1)

m=0;

break;

else

j++;

p=0;

if(p<=1)

m=(Math.pow(-1,c));

System.out.println("The output of function is"+(int)m);

}
PROGRAM

Write a program to input a set of ‘n’ numbers (ascending orders)in a single Dimension Array.
Enter a number and search whether the number and search whether the number is present or not
by using binary search technique. If the number is present then display a message ”Element
found” otherwise, display “Element is not found”.

import java.util.*;

class B_Search

public static int bsearch(int x[],int l,int h,int ele,int f)

int mid;

mid=(l+h)/2;

if(l>h||f==1)

return(f);

else

if(ele==x[mid])

f=1;

if(ele<x[mid])

l=mid-1;

if(ele>x[mid])

l=mid+1;

return(bsearch(x,l,h,ele,f));

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter size of array");

int n=sc.nextInt();
int a[]=new int[n];

System.out.println("Enter element of array");

for(int i=0;i<n;i++)

a[i]=sc.nextInt();

System.out.println("Enter element to be search");

int k=sc.nextInt();

int l=0,h=n-1;

int f=0;

int res=bsearch(a,l,h,k,f);

if(res==1)

System.out.println("Element is found");

else

System.out.println("Element is not found");

}}
PROGRAM

Write a program in java to input number N (1<=N<=200) and display all the Harshad Number
Niven Number in the range from 1 to N then(both inclusive) .

Harshad Number :In recreational mathematics,Harshad Number ( or Niven Number), is an


integer (in base 10) that is divisible by the sum of its digits .

import java.util.*;

class HarshadNumber

public static void main(String args[])

Scanner sc= new Scanner(System.in);

System.out.print("Enter a number:");

int n=sc.nextInt();

int c=n,d,sum=0;

//finding sum of digts

while(c>0)

d=c%10;

sum=sum+d;

c=c/10;

if(n%sum==0)

System.out.println(n+"is a Harshad Number.");

else

System.out.println(n+"is not a Harshad Number.");

}
PROGRAM

Write a program to input two decimal numbers m,n (m>0,n>0 and they are long integer
type).Convert the decimal number into its equivalent binary numbers.,Add the binary numbers
and display their sum in binary form.

import java.util.*;

class Binary

double toBinary(long dec)

double bin=0;

int c=0;

while(dec>0)

bin=bin+(dec%2)*Math.pow(10,c++);

dec=dec/2;

return(bin);

double addBinary(long bin1,long bin2)

long sum,carry=0,bit1,bit2,ct=0;

double total=0.0;

while(bin1!=0)

bit1=bin1%10;

bit2=bin2%10;

if((bit1+bit2+ct)%2==0)

sum=1;
else

sum=1;

if((bit1+bit2+ct)>=2)

ct=1;

else

ct=0;

total=total+sum*Math.pow(10,carry++);

bin1=bin1/10;

bin2=bin2/10;

total=total+ct*Math.pow(10,carry);

return(total);

public static void main(String args[])

Scanner sc=new Scanner(System.in);

long m,n,t;

long bin1,bin2;double bin;

System.out.println("Enter a decimal number");

m=sc.nextInt();

System.out.println("Enter another decimal number");

n=sc.nextInt();

Binary ob=new Binary();

bin1=(long)ob.toBinary(m);

bin2=(long)ob.toBinary(n);

bin=ob.addBinary(bin1,bin2);

t=(long)bin;
System.out.println("Binary of"+m+":"+bin1);

System.out.println("Binary of"+n+":"+bin2);

System.out.println("The sum of binary numbers:"+t);

}
CONCLUSION

This project has been a great tutor as far as practical aspects of programming are concerned. I Planned
the program with my classmates and then discussed it with my teachers. After drafting the source
code, I punched in the computer followed by debugging and testing it both at home and school.
Subsequently, I was able to get an error free code to put in my project.

This has not only drilled me in the subject but also taught me things like teamwork, team
management, and research work and presentation skills. These are the lesson for my life, which will
always stays with me and help in my career.
BIBLIOGRAPHY

 Computer Science with Sumita Arora ,DhanpatRai and Company


 Understanding Computer Science by Vijay Kumar Pandey and Dilip Kumar, APC
 Together with Computer science(Question Bank)
 School Java Programming(Question Bank)

You might also like