Page 3 :
import java.util.*;, class count, {, int l,i,cap=0,sm=0,d=0,sp=0;char c;String s;, void main(), {, Scanner sc=new Scanner(System.in);, System.out.println("Enter a string");, s=sc.nextLine();, l=s.length();, for(i=0;i<l;i++), {, c=s.charAt(i);, if(Character.isUpperCase(c)), // (c>='A' && c<='Z'), cap++;, else if(Character.isLowerCase(c)) //(c>='a' && c<='z'), sm++;, else if(Character.isDigit(c)) //(c>='0' && c<='9'), d++;, else, sp++;, }, System.out.println("Capital letters="+cap);, System.out.println("Small letters="+sm);, System.out.println("Digits="+d);, System.out.println("Special characters="+sp);, }, }, , Input a word in uppercase and check for the position, of the first occurring vowel and perform the, following operation., , (i) Words that begin with a vowel are concatenated, with “Y”., For example, EUROPE becomes EUROPEY., (ii) Words that contain a vowel in-between should, have the first part from the position of the vowel till, the end, followed by the part of the string from, beginning till the position of the vowel and is, concatenated by “C”. For example, PROJECT, becomes OJECTPRC., (iii) Words which do not contain a vowel are, concatenated with “N”. For example, SKY becomes, SKYN., , COMBINED ICSE 246 Page 3
Page 6 :
class PALIN, {, int l,i;, String w="",str="",rev="";, char c,c1;, void main(String s), {, s=s+" ";, l=s.length();, for(i=0;i<l;i++), {, c=s.charAt(i);, if(c!=' '), w=w+c;, else, {, c1=w.charAt(0);, str=str+c1;, rev=c1+rev;, w="";, }, }, if(str.equalsIgnoreCase(rev)), System.out.println("Palindrome String");, else, System.out.println("not Palindrome String");, }, }, , A class Rearrange has been defined to modify a word by bringing all the vowels in the word at the beginning, followed by the consonants. [10], Example: ORIGINAL becomes OIIARGNL, , Design a class Exchange to accept a word and interchange the first, alphabet with the last alphabet, with single-letter, word remaining unchanged., , COMBINED ICSE 246 Page 6
Page 7 :
class interchange, {, void main(String s), {, int l=s.length();, if(l==1), System.out.println(s);, else, System.out.println(s.charAt(l-1)+s.substring(1,l-1)+s.charAt(0));, }, }, A sequence of Fibonacci strings is generated as follows:, S1 = “a”,, S2 = “b”,, Sn = S(n-1) + S(n-2), where „+‟ denotes concatenation. Thus the sequence is:, a, b, ba, bab, babba, babbabab,……. n terms., class fibo, {, int i;String x,y,z;, void main(int n), {, x="a";, y="b";, System.out.print(x+" "+y);, for(i=1;i<=n-2;i++), {, z=y+x;, System.out.print(" "+z);, x=y;, y=z;, }, }, }, Write a program in Java to accept a word/a String and display the new string after removing all the vowels, present in it., Sample Input:, COMPUTER APPLICATIONS, Sample Output:, CMPTR PPLCTNS, , class remove, {, int l,i;char c;String newstr="";, void main(String s), {, l=s.length();, for(i=0;i<l;i++), {, c=s.charAt(i);, if(c!='A'&&c!='E'&&c!='I'&&c!='O'&&c!='U'), newstr=newstr+c;, }, System.out.print(newstr);, }, }, , COMBINED ICSE 246 Page 7
Page 8 :
Write a program in Java to enter a String/Sentence and display the longest word and the length of the longest word, present in the String., Sample Input: “TATA FOOTBALL ACADEMY WILL PLAY AGAINST MOHAN BAGAN”, Sample Output: The longest word: FOOTBALL: The length of the word: 8, , class longest, {, int l,i,len;char c;String w="",large;, void main(String s), {, large="";, len=0;, s=s+" ";, l=s.length();, for(i=0;i<l;i++), {, c=s.charAt(i);, if(c!=' '), w=w+c;, else, {, if(w.length()>large.length()), {, large=w;, len=w.length();, }, w="";, }, }, System.out.print("largest word is "+large+" and its length is "+len);, }, }, , class longest, {, int l,i,len;char c;String w="",small;, void main(String s), {, small=s;, len=0;, s=s+" ";, l=s.length();, for(i=0;i<l;i++), {, c=s.charAt(i);, if(c!=' '), w=w+c;, , COMBINED ICSE 246 Page 8
Page 9 :
if(c!=' '), w=w+c;, else, {, if(w.length()<small.length()), {, small=w;, len=w.length();, }, w="";, }, }, System.out.print("smallest word is "+small+" and its length is "+len);, , }, }, , Write a program to input a sentence and display the word of the sentence that contains maximum number, of vowels. Sample Input: HAPPY NEW YEAR, Sample Output: The word with maximum number of vowels: YEAR, , Consider the sentence as given below: Blue bottle is in Blue bag lying on Blue carpet Write a program to assign the, given sentence to a string variable. Replace the word Blue with Red at all its occurrence. Display the new string as, shown below: Red bottle is in Red bag lying on Red carpet, , COMBINED ICSE 246 Page 9
Page 10 :
class replac, {, int l,i;char c;String w="",newstr="";, void main(), {, String s="Blue bottle is in Blue bag lying on Blue carpet";, s=s+' ';, l=s.length();, for(i=0;i<l;i++), {, c=s.charAt(i);, if(c!=' '), w=w+c;, else, {, if(w.equalsIgnoreCase("Blue")), newstr=newstr+"Red"+" ";, else, newstr=newstr+w+" ";, w="";, }, }, System.out.println(newstr);, }, }, , Write a program to accept a word and convert it into lower case, if it is in upper case. Display the new word by, replacing only the vowels with the letter following it., Sample Input: computer, Sample Output: cpmpvtfr, , A string is said to be „Unique‟ if none of the letters present in the string are repeated. Write a program to, accept a string and check whether the string is Unique or not. The program displays a message accordingly., Sample Input: COMPUTER, Sample Output: Unique String, class uniq, {, int flag=0,l,ctr,j;char i,c;, void main(String s), {, l=s.length();, for(i='A';i<='Z';i++), , COMBINED ICSE 246 Page 10
Page 11 :
{, ctr=0;, for(j=0;j<l;j++), {, c=s.charAt(j);, if(c==i), ctr++;, }, if(ctr>1), {, flag=1;, break;, }, }, if(flag==0), System.out.print("It is a uniue string");, else, System.out.print("It is not a uniue string");, }, }, , class alpha, {, int l,ctr,j;char i,c;, void main(String s), {, l=s.length();, System.out.println("Alphabet\tFreuency");, for(i='A';i<='Z';i++), {, ctr=0;, for(j=0;j<l;j++), {, c=s.charAt(j);, if(c==i ||c==(char)(i+32)), ctr++;, }, if(ctr!=0), System.out.println(i+"\t"+ctr);, }, }, }, , COMBINED ICSE 246 Page 11