Icse Bluej String Handling Programs
Icse Bluej String Handling Programs
YOUNG MINDS
ACADEMY
Guilding Bright
Brains
Program 1. Accept a name and print it in reverse form. Hint : (If name is AMIT, then output
is TIMA)
class ques1
String n = "AMIT";
int l = n.length();
System.out.print (n.charAt(i));
2. WAP to accept a name. Then display the ASCII value of each character present in that
name.
class ques2
String n = "AMITABH";
int l = n.length();
for(int i = 0;i<l;i++)
}
3. WAP to read a word. Print the position of the first vowel occurring in the word.
class ques3
String n = "AMITABH";
int l = n.length();
int p = 0;
for(int i = 0;i<l;i++)
char c = n.charAt(i);
p = i+1;
break;
}
if(p = = 0)
else
}
4. WAP in BASIC to take a proverbial statement (like 'Failure are the pillars of success')
as an input from the user and then output the frequency of the vowels occurring in the
statement.
class ques4
for(int i = 0;i<n.length();i++)
char c = n.charAt(i);
}
5. WAP to enter any sentence and calculate the following:
d) Total number of special character used in it. e) Total number of vowels presents in
it.
class ques5
int l = n.length();
for(int i = 0;i<l;i++)
char c = n.charAt(i);
nd++;
cl++;
sl++;
ns++;
if(c = = 'A'||c = = 'a'|| c = = 'E'||c = = 'e'||c = = 'I'|| c = = 'i'||c = = 'O'|| c = = 'o'||c = = 'U'||c = = 'u')
nv++;
if(Character.isLowerCase(c))
c = Character.toUpperCase (c);
if(pos! = -1)
alp = alp.replace(c,'0');
alpha++;
6. Write programs to accept any word and check whether the word is palindrome or not.
class ques6
String ow = "MALAYALAM";
String rw = "";
int l = ow.length();
rw = rw+ow.charAt(i);
if(ow.compareTo(rw) = = 0)
else
7. WAP to accept a name (in first name & last name format), then display that name in
short format.
class ques7
System.out.print (n.charAt(0)+".");
System.out.print (n.substring(p));
string variable and then display in short form. (Example - ARUP KUMAR DAS becomes A.
K. DAS)
class ques8
firstSpace++;
System.out.print (name.charAt(firstSpace)+".");
System.out.print (name.substring(secondSpace));
(without using library function). For example: Input: MY NAME IS SUMIT Output: my
name is sumit
class ques9
String u = "";
for(int i = 0;i<n.length();i++)
char c = n.charAt(i);
u = u+c;
10. WAP to accept any name (full name) and convert it to Proper Case.
class ques10
n = n.toLowerCase();
for(int i = 1;i<n.length();i++)
else
properCase = properCase+n.charAt(i);
11. WAP to accept any string and then convert each 'A' to 'AN' present in that string. Then
print the string. (Note: remember 'A' should not be a part of a word?).
class ques11
{
String n = "I AM A GOOD BOY";
String s = "";
n = n+" ";
int p = 0,x;
while(p<n.length())
x = n.indexOf(' ',p);
if(word.compareTo("A") = = 0)
s = s+" "+"AN";
else
s = s+" "+word;
p = x+1;
12. Sankalp has a terrible habit of deleting the last two letters of a word beginning with 'E'
and adding a single letter 'O' in their place. WAP to convert a given word Exterminate or
Ellipse according to Sankalp habit.
class ques12
String w = "EXTERMINATE";
int l = w.length();
else
TROUBLE becomes OUBLETRAY as so on. The first vowel of the original word becomes
the starting of the translation and proceeding letter being shifted towards the end and
followed by AY. Word that begins with a vowel is left unchanged. WAP to accept a word
and convert in to Piglatin word.
class ques13
String n = "TROUBLE";
int p = 0,i;
for(i = 0;i<n.length();i++)
char c = n.charAt(i);
}
14. Accept two strings, a word and a sentence. Then find number of times the word is
present in given string. If I enter 'THE' and 'THE BIG FAT THE ODORE', then the computer
should display 2.
class ques14
n = n+" ";
String w = "THE";
int p = 0,x,ctr = 0;
while(p<n.length())
x = n.indexOf(' ',p);
if(w.compareTo(word) = = 0)
ctr++;
p = x+1;
15. WAP to accept a sentence then convert each character to second next character. The
character A becomes C, Y becomes A and Z becomes B.
class ques15
for(int i = 0;i<n.length();i++)
asc+ = 2;
else
if(asc = = 89)
asc = 65;
else
if(asc = = 90)
asc = 66;
System.out.print ((char)asc);
16. A name is to be said as odd name if the ASCII code of each character become an odd
number. Write a program to accept a name and check whether the given name is odd
name or not.
class ques16
{
String n = "MOUSUMI";
int flag = 0;
for(int i = 0;i<n.length();i++)
if(asc%2 = = 0) flag = 1;
if(flag = = 0)
else
class ques17
n = n+" ";
String rs = "";
int p = 0,x;
while(p<n.length())
{
x = n.indexOf(' ',p);
String w = n.substring(p,x);
rs = w+" "+rs;
p = x+1;
18. Write a program to accept a binary number and convert it to decimal number. Also
convert each binary digit to its compliment and then convert it to decimal number.
class ques18
String b = "1010111";
String cb = "";
int l = b.length();
if(b.charAt(i) = = '1')
{
dec = dec+(1*tp);
cdec = cdec+(0*tp);
else
dec = dec+(0*tp);
cdec = cdec+(1*tp);
tp* = 2;
if(b.charAt(i) = = '1')
cb = "0"+cb;
else
cb = "1"+cb;