Computer Applications Isc Project
Computer Applications Isc Project
An encoded text can be decoded by finding actual character for the given ASCII
Write a program to input an encoded text having only sequence of ASCII values
without any spaces. Any code or value which is not in the range (65-90 or 97-1 22 or
32-for space) will be ignored and should not appear in the output message. It is
assumed that none the additional value is given in the coded text. Decode the
encoded text and print in the form of sentence. The first alphabet of each word must be in capitals and
rest alphabets will be in smalls only. Any consecutive sets of code
32 will be taken as only one blank space. The output should be exactly in the
following format.
Solution-
import java.io.*;
import java.util.*;
class coding
String cod=buf.readLine();
int length=cod.length();
int ch=0,a1=2,flag=0;
for (int a=0;a<=(length-1);)
{ ch=(Integer.parseInt(cod.substring(a,a1)));
if(((ch>=65)&&(ch<=90))||(ch==32)||((ch>=97)&&(ch<=122)))
{ if (ch1==32)
{ ch=((ch>=65)&&(ch<=90))? ch:(ch-32);
if (ch==32)
continue; }
else
ch=((ch>=65)&&(ch<=90))? (ch+32):ch;
c=(char)ch;
s=s+c;
ch1=ch;
a+=(flag==0)?2:3;
a1+=2;
flag=0; }
else
{ if(flag==0)
{ a1++;
flag=1;
continue; }
else
{ flag=0;
a+=2;
a1++;
continue; } } }
System.out.print("Output(decoded text)\t: ");
for (i=0;st.hasMoreTokens();i++)
Outputs-
coding.main({ });
coding.main({ });
Question 2.
Write a program to input a number (less than 1000) and print the same in figures.
Solution-
import java.io.*;
class figures
{if (n<0)
n=-n;}
if (n>=100)
{if((n/100)>0)
if ((n%100)>0)
tNu((n%100)); }
{if(nn<20)
System.out.println(a[nn]);
else if ((nn>=20)&&(nn<100)&&((nn%10)!=0))
System.out.println(pre[(nn/10)]+" "+a[(nn%10)]);
else if((nn>=20)&&(nn<=100)&&((nn%10)==0))
System.out.println (pre[nn]); }
int n=Integer.parseInt(buf.readLine());
if((n<1000)&&(n!=0))
fig.hundreds(n);
else if (n==0)
System.out.println ("Zero");
Outputs-
figures.main({ });
Question 3.
Sample Dtat
Solution-
import java.util.*;
class primeFactors
int x=0;
while (p.factors[x]!=0)
{ if (p.factors[x+1]!=0)
else
{ a++;
for (;;a++) {
int flag=0;
if (a%b==0)
flag++;
if (flag==2)return(a); } }
if (n==1)factors[0]=1;
int i=0;
while (n!=1)
{ int p=pr.nextPrime();
while (n%p==0)
{ n/=p;
factors[i++]=p; } } } }
Outputs-
primeFactors.mainPrimeFactors({});
primeFactors.mainPrimeFactors({});
Question 4.
Write a program to inherit the class used in question 3 and use it to check weather a number (input by
user) is a Smith number or not.
A Smith number is a composite number, the sum of whose digits is the sum of
factorization. The first few such numbers are 4, 22, 27, 58, 85,94, 121
Sample data-
Smith
Not Smith
Solution-
import java.util.*;
int input=s.nextInt();
if(obj.isSmith(input))
System.out.println ("Smith");
Boolean isSmith(int n)
{ int i=0;
int SODf=0;
primeFactorise(n);
int SODn=sumOfDigits(n);
while(i<factors.length)
SODf+=sumOfDigits(factors[i++]);
if (SODf==SODn)
return true;
{int sum=0;
while (in>0)
sum+=in%10;
in/=10;
return sum;
}}
Outputs-
SmithNumbers.mainSmith({});
Smith
SmithNumbers.mainSmith({});
Not Smith
Question 5.
Write a program to inherit the class used in question 3 and use it to output first n prime numbers (value
of n input by the user) showing appropriate messages.
Sample data-
2,3,5,7,11,13,17,19,23,29.
Solution-
import java.util.*;
x.resetNextPrime();
{ for(int z=0;z<n;z++)
if(z!=n-1)
System.out.print(x.nextPrime() + ",");
else
System.out.print(x.nextPrime() + "."); }
x.resetNextPrime(); } }
Outputs-
PrintPrime.main({ });
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71.
Question 6.
Write a program to find the longest string in a sentence (input by user) assuming that every word is
terminated by a white space and there is only one longest word.
Sample data-
Solution-
import java.util.*;
class Longest
int counter=0;
while(s.hasMoreTokens())
a[counter++]=s.nextToken();
//Bubble sort
for(int i=0;i<a.length;i++)
if (a[j].length()<a[j+1].length())
{ String temp=a[j];
a[j]=a[j+1];
a[j+1]=temp; }
return a[0]; }
Outputs-
Longest.main({ });
Input a sentence here : Mary Had A Little Lamb
Longest.main({ });
Question 7.
Write a program to check weather a number(input by user) is an armstrong number or not using
RECURSIVE TECHNIQUE.
Sample Data-
Not Armstrong
Armstrong
Solution-
import java.io.*;
class ArmstrongRecursive
int a=Integer.parseInt(buf.readLine());
if ((ob1.wow(a)==a)&&(a!=0))
System.out.println ("Armstrong");
else
class armstrong
{int b=0;
{ if (a!=0)
{ b=a;
b/=10;
return ((a%10)*(a%10)*(a%10))+wow(b); }
else
return 0; } }
Output-
ArmstrongRecursive.main({ });
Not Armstrong
ArmstrongRecursive.main({ });
Not Armstrong
ArmstrongRecursive.main({ });
Armstrong
Question 8.
A magic number is a number in which the eventual sum of digits of the number is equal to 1.
Design a class Magic to check if a given number is a magic number. Some of the members of the class
are given below:
n=nn
Specify the class Magic giving details of the constructor, void getnum(int), int
Solution-
import java.io.*;
{long n;
Magic()
{ n=0; }
{ n=nn; }
long sumOfDigits(long a)
{ long s=0;
while (a!=0)
s+=a%10;
a/=10;
}return (s);
void isMagic()
{ long sum=0;
sum=sumOfDigits (n);
while (sum>9)
sum=sumOfDigits (sum);
System.out.println ("Since, the eventual sum of digits of the number "+n+" is "+sum+",");
if (sum==1)
else
try
num=Long.parseLong(buf.readLine());
num=Long.parseLong(buf.readLine());
M.getnum(num);
M.isMagic();
Output
Question 9.
columns.A class Transarray contains a two dimensional integer array of order [mxn]. The maximum
value possible for both m and n is 20. Design a class Transarray to find the transpose of a given matrix.
The details of the members of the class are given below:
Member functions:
Specify the class Transarray giving details of the constructors , vois fillarray(), void
transpose(Transarray) and void disparray(). You need not write the main function.
Solution
import java.io.*;
int m,n;
Transarray()
{}
{m=mm;
n=nn;}
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
arr[i][j]=Integer.parseInt(br.readLine());}}}
void transpose(Transarray A)
{m=A.n;
n=A.m;
{for(int j=0;j<n;j++)
{arr[i][j]=A.arr[j][i];}}}
void disparray()
{for(int i=0;i<m;i++){
for(int j=0;j<n;j++)
{System.out.print(arr[i][j]+"\t");}
System.out.println();}}
{ try{
T1.fillarray();
T2.transpose (T1);
T2.disparray();
catch(Exception e)
{ System.out.println(e); }}}
Output
Transarray.main();
Position [0],[0] : 12
Position [0],[1] : 23
Position [0],[2] : 34
.
12 67 12 67 21
23 78 23 78 32
34 89 34 89 43
45 90 45 90 54
56 1 56 0 65
Question 10.
A library issues books on rental basis at a 2% charge on the cost price of the
bookper day. As per the rules of the library, a book can be retained for 7 days
without any fine. If the book is returned after 7 days, a fine will also be charged for
1 to 5 2.00
6 to 10 3.00
Design a class Library and another class Compute to perform the task. The details
Member functions:
Member functions:
Specify the class Library giving details of the constructors and void show(). Using
the concept of Inheritance, specify the class Compute giving details of constructor,
Solution
import java.io.*;
import java.util.*;
class Library
String name,author;
float price;
this.name=name;
this.author=author;
this.price=price;
void show()
{
int d;
float fine;
super(name,author,price);
this.d=d;
fine=0;
void fine()
fine=2f*d;
fine=5*2f+3f*(d-5);
else
fine=5*2f+5*3f+5f*(d-10);
void display()
show();
System.out.println("Fine\t: Rs."+fine+"/-");
String name=s.nextLine();
String author=s.nextLine();
float price=s.nextFloat();
int d=s.nextInt();
System.out.print("_____________________________________\n");
ob.display();
Output
Compute.main({ });
Input Price : 45
_____________________________________
Fine : Rs.70.0/-
Question 11.
To input a string (precoded), coded by replacing each character with the character which comes 'n'
characters after it, and decode it using an input defining the number of characters to shift by.
Sample data-
Enter the encoded string : FQNJSX%FWJ%HTRNSL%&&
Solution
import java.io.*;
class decode
String enc;
enc=in.readLine();
String dec="";
int sh=0;
sh=Integer.parseInt(in.readLine());
enc=enc.toUpperCase();
int l=enc.length();
for(int i=0;i<l;i++)
int k=enc.charAt(i),n=0;
k+=sh;
for(;;)
k=65+n-1;
else
break;
if(i+1!=l)
int k1=enc.charAt(i+1),n1=0;
k1+=sh;
for(;;)
if(k1>90)
n1=k1-90; // convert
k1=65+n1-1;
else
break;
}
if(k==81 && k1==81)
dec=dec+" ";
Output
decode.main({ });
decode.main({ });
decode.main({ });
input amount, upto 5 digits. The available denomination with the bank are
Design a program to accept the amount from the user and display the
Example 1:
INPUT: 14836
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
EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT
Solution
import java.io.*;
class Bank
int rev=0,amount,dummy;
amount=Integer.parseInt(br.readLine());
if(amount >99999)
System.out.println("Invalid Amount...");
return;
dummy=amount;
while(dummy >0)
rev=rev*10+dummy%10;
dummy=dummy/10;
while(rev >0)
{
switch(rev%10)
case 0:
System.out.print(" ZERO");
break;
case 1:
System.out.print(" ONE");
break;
case 2:
System.out.print(" TWO");
break;
case 3:
System.out.print(" THREE");
break;
case 4:
System.out.print(" FOUR");
break;
case 5:
System.out.print(" FIVE");
break;
case 6:
System.out.print(" SIX");
break;
case 7:
System.out.print(" SEVEN");
break;
case 8:
System.out.print(" EIGHT");
break;
case 9:
System.out.print(" NINE");
break;
rev=rev/10;
System.out.println("\nDENOMINATORS:\n");
rev=amount/1000;
if(rev!=0)
amount=amount%1000;
rev=amount/500;
if(rev!=0)
amount=amount%500;
rev=amount/100;
if(rev!=0)
amount=amount%100;
rev=amount/50;
if(rev!=0)
System.out.println("50 X " + rev + " = " + rev*50);
amount=amount%50;
rev=amount/20;
if(rev!=0)
amount=amount%20;
rev=amount/10;
if(rev!=0)
amount=amount%10;
rev=amount/5;
if(rev!=0)
amount=amount%5;
rev=amount/2;
if(rev!=0)
amount=amount%2;
rev=amount/1;
if(rev!=0)
Output
25648
DENOMINATORS:
1000 X 25 = 25000
500 X 1 = 500
100 X 1 = 100
20 X 2 = 40
5X1=5
2X1=2
1X1=1
Question 13.
Given the two positive integers p and q, where p < q. Write a program to determine how many kaprekar
numbers are there in the range between 'p' and 'q' (both inclusive) and output them.
A positive whole number 'n' that has 'd' number of digits is squared and split into
2 pieces, a right hand piece that has 'd' digits and a left hand piece that has
remaining 'd' or 'd-1' digits. If sum of the pieces is equal to the number then
SAMPLE DATA:
INPUT:
p=1
Q=1000
OUTPUT:
1,9,45,55,99,297,999
Solution
import java.io.*;
class karpekar
{ int i,p,q,c=0;
int num;
p=Integer.parseInt(br.readLine());
q=Integer.parseInt(br.readLine());
if(p >=q)
{ System.out.println("Wrong Entry...");
return; }
for(i=p;i<=q;i++)
{ show(i); }
System.out.println("\nFREQUENCY OF KAPREKAR NUMBERS IS:"+c); }
while(no >0)
{ digit++;
no=no/10; }
no=num;
while(digit > 0)
{ rev=rev*10+no%10;
no=no/10;
digit--; }
// 'rev' holds the right part in reverse order and 'no' holds the left part
rev=reverse(rev);
if((rev+no)==x)
{ System.out.print(" "+x);
c++; } }
{ int r=0;
while(n > 0)
{ r=r*10+n%10;
n=n/10; }
return r; }}
Output
karpekar.take();
500
1 9 45 55 99 297
Question 14.
Input a paragraph containing n number of sentences where (1<=n<=4). The words are to be separated
with single blank space and are in upper case.
A sentence may be terminated either with a full stop (.) or question mark (?).
(i) Enter the number of sentences, if it exceeds the limit show a message.
Solution
import java.io.*;
import java.util.*;
class Sentences
n=Integer.parseInt(br.readLine());
if(n< 1 || n >4)
{ System.out.println("Wrong Input");
return;}
str=br.readLine();
n=st.countTokens();
sarr=new String[n];
strarr=new String[n];
fre=new int[n];
while(st.hasMoreTokens())
{sarr[index++]=st.nextToken();}
for(i=0;i< index-1;i++)
{for(j=i+1;j< index;j++)
{if(sarr[i].compareTo(sarr[j]) > 0)
{s=sarr[i];
sarr[i]=sarr[j];
sarr[j]=s;}}}
c=1;
s=sarr[0];
for(i=1;i< index;i++)
{if(!s.equals(sarr[i]))
{strarr[index1]=s;
fre[index1++]=c;
c=1;
s=sarr[i];}
else
c++;}
strarr[index1]=s;
fre[index1++]=c;
for(i=0;i< index1-1;i++)
{for(j=i+1;j< index1;j++)
{n=fre[i];
fre[i]=fre[j];
fre[j]=n;
s= strarr[i];
strarr[i]=strarr[j];
strarr[j]=s;}}}
System.out.println("WORD\t\t\tFREQUENCY");
for(i=0;i< index1;i++)
System.out.println(strarr[i]+"\t\t\t"+fre[i]);}}
Output
Sentences.take();
WORD FREQUENCY
And 1
Democracy 1
It 1
by 1
for 1
it 1
of 1
is 3
people 3
the 3
Question 15.
The co-ordinates of a point P on a two dimensional plane can be represented by P(x,y) with x as the x-
coordinate and y as the y-coordinate. the coordinates of midpoint of two points P1(x1,y1) and P2(x2,y2)
can be calculated as P(x,y) where
Member Functions
Point midpoint(Point A , Point B) : Calculates and returns the midpoint of the two points A
and B.
Specify the class Point giving details of the constructor(), member functions
voidreadpoint(), Point midpoint(Point, Point) and void displaypoint() along with the main() function to
create an object and call the functions accordingly to calculate the midpoint between any two given
points.
Solution
import java.io.*;
class Point
{ double x,y;
Point()
{ x=0;
y=0; }
{ x=this.x;
y=this.y; }
x=Double.parseDouble(buf.readLine ());
System.out.print("value of y\t:");
y=Double.parseDouble(buf.readLine ()); }
{ x=(A.x+B.x)/2;
y=(A.y+B.y)/2;
return ret; }
void displaypoint()
{ System.out.println ("("+x+","+y+")"); }
{try {
point1.readpoint();
point2.readpoint();
Point x=point1.midpoint(point1,point2);
point1.displaypoint(); }
catch (Exception e)
Output
Point.main();
value of x :2
value of y :3
value of x :4
value of y :5
(3.0,4.0)
Question 16.
String = holiday
h_y
ho_ay
hol_day
holi_iday
holid_liday
holida_oliday
holiday_holiday
holida_oliday
holid_liday
holi_iday
hol_day
ho_ay
h_y
Solution
import java.io.*;
class pattern
String S="";
S=in.readLine();
int a,i,j,k=-1,s=n-1,m=n;
System.out.println();
System.out.print(" ");
System.out.print(S.charAt(i));
System.out.print(S.charAt(j));
s=0;k=n-2;m=1;
for(a=1;a<=n;a++)
System.out.print(" ");
s++; // counter
System.out.print(S.charAt(i));
k--; // counter
System.out.print("_");
System.out.print(S.charAt(j));
m++; // counter
OUTPUT :
Enter the string
cricket
c_t
cr_et
cri_ket
cric_cket
crick_icket
cricke_ricket
cricket_cricket
cricke_ricket
crick_icket
cric_cket
cri_ket
cr_et
c_t
Question 17.
Write a program to input a string and to print it in lexicographical order of characters. The program
should also ask the user weather he wants to try again.
Sample Data
No
Solution
import java.io.*;
class alphabet
{ byte z=1;
while(z==1)
String S=s.readLine();
System.out.println("Try Again?");
if (s.readLine().equalsIgnoreCase("yes"))
{z=1;}
else z=0; } }
{ String newString="";
S=S.toLowerCase();
s[i]=S.charAt(i);
for (int j=0;j<s.length-1;j++)
{ if(s[i]>s[i+1])
{ char temp=s[i];
s[i]=s[i+1];
s[i+1]=temp; } }
newString+=(s[i]);
return newString; }}
Output
alphabet.main({ });
Try Again?
yes
Try Again?
No
Question 18.
Write a program to input a string and output the reverse of the string input by the user.
Sample Data
Anthony Gonzalves
Solution
import java.io.*;
class StringReverser
String s,s1;
s=St;
s1="";
int l=s.length();
int pos=l-1;
while (pos>(-1))
s1=s1+(s.charAt(pos));
pos--;
return s1;
{
BufferedReader buf=new BufferedReader(new InputStreamReader (System.in));
String in=buf.readLine();
Output
StringReverser.main({ });
Anthony Gonzalves
StringReverser.main({ });
Madam is Malayalam
Question 19.
Write a program to inherit the class used in question 18 and to use it to check weather a number is
pallindrome or not.
Sample Data-
Malayalam
Pallindrome
Not Pallindrome
Solution
import java.io.*;
if(rev.reverseString(s).equalsIgnoreCase(s))System.out.println ("Pallindrome");
pal.pallindrome(buf.readLine());
Output
StringPallindrome.main({ });
Titanic
Not Pallindrome
StringPallindrome.main({ });
Tet a tet
Pallindrome
Question 20.
Write a menu driven program to output the value of nCr or nPr (as in permutation and combination)
Solution
import java.util.*;
int fact=1,F=0,P=0,C=0;
if (num>0)
fact*=num;
else {
F=fact;
fact=1;
return F;
System.out.println (C);
return C;
P=factorial (n)/factorial(n-r);
System.out.println (P);
return P;
int n,r;
n=s.nextInt();
r=s.nextInt();
cp=s.next();
if (cp.equalsIgnoreCase("C"))
o.combination(n,r);
else if (cp.equalsIgnoreCase("P"))
o.permutation(n,r);
else
System.out.println ("Invalid Input \n"+cp+" is not a valid input\nInput C for combination or input
P for permutation");
Output
PnC.main({ });
PnC.main({ });
Input the value of n
10
Question 21.
Write a java class to input the name ans class of 10 students and output the same in tabular forn in a file
"Student List.txt".
Solution
import java.io.*;
class File
try
pw.println ("\tName\t|\tClass\n\t--------+-----------");
while(a<11){
System.out.print("Enter Name\t:");
name=br.readLine();
System.out.print("Enter Class\t:");
Class=br.readLine();
pw.println ("\t"+name+"\t|\t"+Class);
a++;}
pw.close();
bw.close();
fw.close();
catch(Exception e)
System.out.println (e);
Output
fileOper1.main();
Name | Class
----------+-----------
Gaurav | 12th
Dhaval | 12th
Siddhart | 11th
Nandan | 10th
Bharat | 6th
Question 22.
A class Decioct has been defined to convert a decimal number int its octal equivalent.
Class Name
DeciOct
oct
Member Functions:
DeciOct()
n=0, oct=0.
void deci_oct()
Calculates the octal equivalent of 'n' and stores it in oct USING RECURSIVE TECHNIQUE.
void show()
Displays the decimal number 'n', calls the function deci_oct() and displays its octal equivalent.
Specify the class DeciOct, giving details of the constructor, void getnum(int), void deci_oct() and void
show(). Also define a main() function to create an object and call the functions accordingly to enable the
task.
Solution
import java.util.*;
class DeciOct
{ int n1;
int n;
int oct;
int p=0;
DeciOct()
{ n=0;
n1=0;
oct=0; }
void getnum(int nn)
{ n1=nn;
n=nn; }
void deci_oct()
{ if(n1!=0)
{ oct=10*oct+(n1%8);
n1=n1/8;
deci_oct(); } }
void show()
o.getnum(s.nextInt());
o.deci_oct();
o.show(); }}
Output
DeciOct.main({ });
DeciOct.main({ });
Decimal Number : 39
Octal Equivalent : 74
Question 23.
Input a sentence from the user and count the number of times an and and are present in the sentence.
Design a class Frequency to perform the above task.
Class Name
Frequency
text
countand
countan
len
Member Functions:
Frequency()
To assign the value of 'n' to 'text' where the value of parameter should be in lower case.
void checkandfreq()
void checkanfreq()
void display()
Displays the respective frequencies of "an" and "and" giving appropriate messages.
Specify the class Frequency, giving details of the constructor, void accept(String), void checkandfreq() ,
void checkanfreq() and void display(). Also define a main() function to create an object and call the
functions accordingly to enable the task.
Solution
import java.util.*;
class Frequency
String text;
int countan,countand,len;
Frequency()
countan=0;
countand=0;
len=0;
text="";
}
void accept(String n)
text=n.toLowerCase();
void checkandfreq()
while(s.hasMoreTokens())
if(s.nextToken().equalsIgnoreCase("and"))
countand++;
void checkanfreq()
while(s.hasMoreTokens())
if(s.nextToken().equalsIgnoreCase("an"))
countan++;
}
}
void display()
try{obj.accept(s.nextLine());
obj.checkanfreq();
obj.checkandfreq();
obj.display();
catch (Exception e)
System.out.println (e); } }}
Output
Frequency.main({ });
Frequency of an :1
Frequency of and :2
Question 24.
A super class Worker has been defined to store the details of a worker. Define a subclass Wages to
compute the monthly wages of the worker. The details/specifications of both classes are given below:
Class Name
Worker
Name
Basic
Member Functions:
Worker()
void display()
Class Name
Wages
Hrs
Stores the hours worked.
Rate
Wage
Member Functions:
Wages()
Double overtime()
void display()
Specify the class Worker, giving details of the constructor and void display(). Using the concept of
inheritance. specify a class Wages giving details of the constructor, double overtime() and void
display().Write an appropriate main() function.
Solution
class worker
String Name;
Double Basic;
Name=name;
Basic=basic;
void display()
double hrs,rate,wage;
super(name,basic);
hrs=Hrs;
rate=Rate;
wage=0;
}
double overtime(){
return (hrs*rate);
void display(){
wage=o.overtime()+Basic;
super.display();
Output
wages.display();
Wage : 6000.0
Question 25.
Input a word in uppercase and check for the position of the first occuring vowel and perform the
following operation.
(1) Words that begin with a vowel are cocatenated with "Y".For example , EUROPE becomes
EUROPEY.
(2) Words that contain a vowel in-between should have the first part from the position of the vowel
till end, followed by the part of the string frombeginning till position of the vowel and is concatenated
with "C". For example PROJECT becomes OJECTPRC.
(3) Words which do not contain vowel are concatenated with "N".
Design a class Rearrange using the description of the data members and member functions given below:
Class Name
Rearrange
Txt
Cxt
len
Member Functions:
Rearrange()
void readword ()
void convert ()
Converts the word into its changed form and stores it in String Cxt.
void display ()
Solution
import java.util.*;
class Rearrange
{ String Txt,Cxt;
int len;
Rearrange()
len=0; }
void readword()
Txt=s.next().toUpperCase();
len=Txt.length(); }
void convert()
int posVovel=0;
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
{ Cxt=Txt+'Y'; }
else
{ c=Txt.charAt(x);
if (c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
{ posVovel=x;
break; }}
if (posVovel!=0)
{ Cxt=Txt.substring(posVovel)+Txt.substring(0,posVovel)+'C'; }
else
{ Cxt=Txt+"N"; } } }
void display()
{ System.out.println("_______________________________________________________________");
object.readword();
object.convert();
object.display(); } }
Output
1) Rearrange.main();
________________________________________________________________
Original word : GAURAV
2) Rearrange.main();
________________________________________________________________
3) Rearrange.main();
________________________________________________________________
4) Rearrange.main();
________________________________________________________________
Question 26.
Write a program to check wheather a given number is a "Perfect Number" or not. A perfect number is
the one whose factors (including 1 and excluding the number itself), add up to give the number itself.
For Example-
6 is a perfect number
28 is a perfect number
Solution
import java.io.*;
class PerfectNumber
int no,sum=0,i;
no=Integer.parseInt(br.readLine());
for(i=1;i<no;i++)
if(no%i==0)
sum=sum+i;
if(sum==no)
obj.takeNumber();
} }
Output
PerfectNumber.main({ });
PerfectNumber.main({ });
28 is a perfect number
PerfectNumber.main({ });
Question 27.
Write a program to input from the user, a square matrix of the size of user's choice and check wheather
the matrix is a wonderous square or not. Also print the prime numbers present in the matrix along with
their row and column number in tabular form.
Solution
import java.io.*;
class WonderousSquare
int arr[][],arr1[];;
int n,i,j,x=0,r,c;
int flag;
n=Integer.parseInt(br.readLine().trim());
arr=new int[n][n];
arr1=new int[2*n];
for(i=0;i< n;i++)
for(j=0;j< n;j++)
arr[i][j]=Integer.parseInt(br.readLine());
}
System.out.println("\nThe matrix is\n");
for(i=0;i< n;i++)
r=0;
c=0;
for(j=0;j< n;j++)
System.out.print(arr[i][j]+" ");
r=r+arr[i][j];
c=c+arr[j][i];
System.out.println();
arr1[x]=r;
arr1[x+n-1]=c;
x++;
for(i=0;i< x;i++)
break;
if(i==x)
else
for(i=0;i< n;i++)
for(j=0;j< n;j++)
if(prime(arr[i][j]))
int index;
for(index=2;index< no;index++)
if(no%index==0)
break;
if(index==no)
return true;
else
return false;
}
public static void main(String args[])throws Exception
ob.take();
Output
WonderousSquare.main({ });
The matrix is
1 2
3 4
2 0 1
3 1 0
Question 28.
Write a class Anagram to print all possibe anagrams of a word input by the user. Also print the number
of possible anagrams of the word.
Solution
import java.io.*;
public class Anagrams
String str;
int counter=0;
str=br.readLine();
show("", str);
if(str.length()<= 1)
counter++;
System.out.println(s+str);
else
} } }
ob.take();}}
Output
Anagrams.main({ });
pat
pat
pta
apt
atp
tpa
tap
Question 29.
Write a program to check wheather a number is automorphic or not. An automorphic number is the one
whose square ends with the number itself.
For example, 25 is an automorphic number. Number of digits in 25 is 2 and square value of 25 is 625. We
have to take 2 extreme right digits from 625 as there are 2 digits in the original entered number. Two
extreme right digits of 625 is 25 which matches with original number 25. So 25 is an automorphic
number. Similarly 5 is also an automorphic number.
Solution
import java.io.*;
class Automorphic
{int i,n,no,sqnum,rev=0,digit=0;
n=Integer.parseInt(br.readLine());
no=n;
do
{digit++;
no=no/10;
} while(no!=0);
sqnum=n*n;}
{do
{rev=rev*10+sqnum%10;
sqnum=sqnum/10;
digit--;
if(digit==0)
break;
} while(true);
rev=reverse(rev);
if(n==rev)
else
{int r=0;
while(n!=0)
{r=r*10+n%10;
n=n/10;}
return r;}
obj.getNumber();
obj.showResult();}}
Output
Automorphic.main({ });
25
25 is an Automorphic number
Automorphic.main({ });
30
Automorphic.main({ });
Enter the number:
5 is an Automorphic number
Question 30.
Write a Menu driven BlueJ program to make a simple calculator which performs addition, substraction,
multiplication and division.
Solution
import java.io.*;
{int a,b,c;
char ch;
a=Integer.parseInt(br.readLine());
b=Integer.parseInt(br.readLine());
ch=(char)br.read();
switch(ch)
{ case '+':
add();
break;
case '-':
sub();
break;
case '*':
product();
break;
case '/':
if(b==0)
else
div();
break;
default:
System.out.println("Wrong Operator");}}
{c=a+b;
System.out.println("Sum="+c);}
{c=a-b;
System.out.println("Subtracted value="+c);}
{c=a*b;
System.out.println("Product="+c);}
{c=a/b;
ob.init(); }}
Output
Pat.main({ });
Product=40
Pat.main({ });
Pat.main({ });
Sum=100
Question 31.
Write a function in java to input two angles in degrees and minutes and find their sum result by passing
them as angle type values to another function. Also define a class Angles to perform the operation.
Write a main(String args[]) function to enable the task.
b = 64 deg 24 min
Solution
import java.io.*;
class angles
deg=Integer.parseInt(in.readLine());
min=Integer.parseInt(in.readLine());
deg=a.deg+b.deg+(int)((a.min+b.min)/60);
min=(a.min+b.min)%60;
o2.accept();
o3.resultAngle(o1,o2);
o3.display();
}}
Output
Enter degrees :
35
Enter minutes :
34
Enter degrees :
245
Enter minutes :
59