DAY 1 Program on concatenation:-
PROGRAM 1
public class Program1{
public void Concat1()
{
String result="";
String a="Samath";
String b="Kumar";
result=a+b;
[Link]("Concatenation of two string is"+result);
}
public void Concat2()
{
String result="";
String a="Samath";
String b="Kumar";
result=[Link](" ");
String result1 = [Link](b);
[Link]("Concatenation of two string is "+result1);
}
}
DAY 2:- program on length and .equals
PROGRAM 2:-
public class Program2
{
public void Length1()
{
String name="Mohit";
int len=[Link]();
[Link]("length of the string is"+len);
}
public void Equals1()
{
String x="Computer";
String y="Science";
boolean z=[Link](y);//false
[Link]("whether Computer is equal to Science "+z);
}
public void Equals2()
{
String x="Computer";
String y="computer";
boolean z=[Link](y);
[Link]("whether Computer is equal to computer "+z);
}}
DAY 3:- program on .compareTo
PROGRAM 3:-
public class Program3
{
public void CompareTo1()
{
String x="Computer";
String y="Science";
boolean z=[Link](y)==0;//false
[Link]("checks whether x and y are equal or not"+z);
}
public void CompareTo2()
{
String x="Computer";
String y="Science";
boolean z=[Link](y)>0;//false
[Link]("checks whether x is greater than y"+z);
}
public void CompareTo3()
{
String x="Computer";
String y="Science";
boolean z=[Link](y)<0;//true
[Link]("checks whether y is greater than x"+z);
}
public void CompareTo4()
{
String x="Cat";
String y="Bat";
int z=[Link](y);//C-B=67-66=01
[Link]("Displays the Ascii value"+z);//1 }
public void CompareTo5()
{
String x="Ca";
String y="Cad";
int z=[Link](y);//d- =100-32=68
[Link]("Displays the Ascii value"+z);//
}}
DAY 4:- program on basic string function
PROGRAM 4:-
public class Program4{
public void IndexOf1()
{
String s="Computer";
int n=[Link]('p');
[Link]("position of p in a Computer is "+n);
//3
}
public void IndexOf2()
{
String s="Malayalam";
int n=[Link]('a');
[Link]("position of a in Malayalam is "+n);
//01
}
public void IndexOf3()
{
String s="malayalam";
int n=[Link]('a',4);
[Link]("position of( a,4) in Malayalam is "+n);
//Output:5-the function returns index of 'a' available in string after 4th index
//at which index next occurence of m is present
}//output 5
public void IndexOf4()
{
String s="Malayalam";
int n=[Link](3,'c');
[Link]("position of (3,'c') in Malayalam is "+n); }}
EXAMPLE:-
public class Example{
public void IndexOf1()
{
String s="Computer";
int n=[Link]('p');
[Link]("position of p in a Computer is "+n);
//3
}
public void IndexOf2()
{
String s="Malayalam";
int n=[Link]('a');
[Link]("position of a in Malayalam is "+n); //01 }}
DAY 5:-
PROGRAM 5:-
public class Program5{
public void CheckLetter()
{
boolean p=[Link]('C');
[Link]("Checks whether a given character is a letter or not "+p);
// true
}
public void CheckNumber()
{
boolean p=[Link]('6');
[Link]("Checks whether a given number is a letter or not "+p);
// false
}
public void CheckDigit()
{
boolean p=[Link]('6');
[Link]("Checks whether a given character is a Digit or not "+p);
//true
}
public void CheckDigit1()
{
boolean p=[Link](6);
[Link]("Checks whether a given character is a Digit or not "+p);
//false
}
public void CheckDigit2()
{
boolean p=[Link]('f');
[Link]("Checks whether a given character is a Digit or not "+p);
//false
}
public void ChecksLetterOrDigit1()
{
boolean p=[Link]('b');
[Link]("Checks whether a given character is a Letter or Digit
"+p);
//true
}}
DAY 6:-
PROGRAM 6:-
public class Program6{
public void CheckLetterorDigit()
{
boolean p=[Link]('C');
[Link]("Checks whether a given character is a letter orDigit "+p);
//true
}
public void Uppercase1()
{
boolean p=[Link]('A');
[Link]("Checks whether a given character is in uppercase or not
"+p);
//output:true
}
public void Lowercase1()
{
boolean p=[Link]('c');
[Link]("Checks whether a given character is in lowercase or not
"+p);
//true
}
public void ToUpperCase1()
{
char p=[Link]('a');
[Link]("Converts a given character to uppercase "+p);
//A
}
public void ToLowerCase1()
{
char p=[Link]('F');
[Link]("Converts a given character to lowercase"+p);
//f
}
public void ToUpperCase11()
{
char p=[Link] ('/');
[Link]("Character in upper case is "+p);
//remains same
}
public void ToUpperCase222()
{
String name="computer";
String result=[Link]();
[Link]("Converts thr given string to uppercase"+result);
//COMPUTER
}
/* public void ToUpperCase111()
{
char p=[Link] ("f");
[Link](" output is "+p);
} */ }
DAY 7:-
PROGRAM 7:-
public class Program7{
public void Touppercase()
{
String a="computer";
String p=[Link]();
[Link]("Converts computer to uppercase "+p);
//output:COMPUTER
}
public void Tolowercase()
{
String a="COMPUTER";
String p=[Link]();
[Link]("Converts COMPUTER to lowercase "+p);
//output:computer
}
public void IsUppercase1()
{
boolean p=[Link]('a');
[Link]("Checks whether a is in uppercase or not "+p);
//output:false
}
public void ToLowercase1()
{
char p=[Link]('C');
[Link]("Converts C to lowercase or not "+p);
//output:c
}
public void Islowercase()
{
boolean p=[Link]('a');
[Link]("checks whether a is in lowercase "+p);
//output:true
}
public void Remainssame()
{
char p=[Link]('f');
[Link]("Converts a f to f"+p);
//output:f
}
public void Remainsame1()
{
char p=[Link] ('F');
[Link]("Converts F to F "+p);
//output:F
}
public void Specialcharacter()
{
String s="Neha_14";
String result=[Link]();
[Link]("special character remains the same"+result);
//output:NEHA_14;
}
public void Iswhitespace()
{
boolean p=[Link](' ');
[Link]("checks whether white space is there or not"+p);
// output:true
}}
EXTRA PROGRAM:-
public class DoubleQuotes
{
public void DQ(){
char A='A';
int n=(int)(A+A);
[Link](+n);
}
}
DAY 8:-
PROGRAM 8:-
public class Program8{
public void LastIndexOf()
{
String s="Malayalam";
int p=[Link]("a");
[Link]("Checks for the last index of a in Malayalam "+p);
//output:07
}
public void Trim1()
{
String a=" COMPUTER APPLICATIONS";
String p=[Link]();
[Link]("trim function doesnot remove middle space"+p);
//COMPUTER APPLICATIONS
}
public void Trim2()
{
String a=" COMPUTER ";
String p=[Link]();
[Link]("_______ COMPUTER-removes the leading space of the
given string "+p);
//COMPUTER
}
public void Trim3()
{
String a="COMPUTER ";
String p=[Link]();
[Link](" COMPUTER________-removes the trailing space of the
given string "+p);
} }
DAY 9:-
PROGRAM 9:-
public class Program9{
public void Endswith()
{
String a="Computer is Fun";
boolean p=[Link]("Fun");
[Link]("Checks whether a given string ends with fun is Computer
is Fun "+p);
//output:true
}
public void Startswith()
{
String a="Fun is COMPUTER";
boolean p=[Link]("Fun");
[Link]("Checks whether a given string starts with Fun is
Computer is Fun "+p);
//output:true
}
public void EqualsIgnoreCase()
{
String a="Computer";
String b="computer";
boolean p=[Link](b);
[Link]("equalsIgnoreCase() will ignore the case "+p);
//output:true
}}
EXTRA:-
public class EIC{
public void E1(){
String a= "Computer";
String b="Computer";
boolean result=[Link]("Computer");
[Link](result);
}}
DAY 10:-
PROGRAM 10:-
public class Program10{
public void Replace1()
{
String a="MALAYALAM";
String p=[Link]('A','X');
[Link]("replaces in a string MALAYALAM A with X "+p);
//MXLXYXLXM
}
/* public void Replace2()
{
String a="MXLXYXLXM";
String p=[Link](3,'X','A');
[Link]("replaces from 3rd index X with A "+p);
//output:MXLAYALAM
}*/
public void Replace3()
{
String a="The green bottle is in green bag";
String p=[Link]("green","Red");
[Link]("Replaces green with Red in a given string "+p);
//output:The Red bottle is in Red bag
}
}
DAY 11:-
PROGRAM 11:-
public class Program11{
public void Substring()
{
String a="computer";
String p=[Link](3);
[Link]("will display all the characters from the third index "+p);
//output://puter
}
public void Substring1()
{
String a="COMPUTER";
String p=[Link](3,6);
[Link]("will display the character including the third index and
excluding the sixth index "+p);
//output:PUT
}
public void CharAt1()
{
StringBuffer n=new StringBuffer("Commuter");
[Link](3,'p');
[Link]("new string is "+n);
//output:Computer
}}}
EXTRA:-
public class StringBufferSetCharAtExample2 {
public void A() {
StringBuffer sb = new StringBuffer("abc");
[Link]("string: " + sb);
[Link](1,'x');
[Link]("character at index 1: " +sb);
//output:axc
} }
DAY 12:-
PROGRAM 12:-
;public class Program12
{
public void Insert()
{
StringBuffer p=new StringBuffer("Computer");
StringBuffer p1=new StringBuffer(" is Fun");
StringBuffer result=[Link](8,p1);
[Link]("new string is "+result);
}}
DAY 13:-
PROGRAM 13:-
public class Program13{
public void Delete()
{
StringBuffer n=new StringBuffer("Computer");
StringBuffer result=[Link](3,6);
[Link]("new string is "+result);
//output:Comer
}
public void Append()
{
StringBuffer n=new StringBuffer("Comp");
StringBuffer p=new StringBuffer("uter");
StringBuffer result=[Link](p);
[Link]("new string is "+result);
//output:Computer
}
public void Reverse(String name)
{
StringBuffer n=new StringBuffer(name);
StringBuffer p=[Link]();
[Link]("new string is "+p);
}
public void Setlength(String name)
{
StringBuffer n=new StringBuffer(name);
[Link](6);
[Link]("length is "+n); }}
DAY 14:-
PROGRAM 14:-
public class Design
{
/* Question 1:To display the output in the following pattern
B
L
U
E
J
*/
public void Design2(String name)
{
int len=[Link]();
for(int i=0;i<len;i=i+1)
{
char result=[Link](i);
[Link](result);
}}}
DAY 15:-
PROGRAM 15:_
/*Question 2:SNOWY PROGRAM
Write a program in java to input any given string and calculate total
characters and vowels present in a given string and reverse it
Sample Input :Snowy
Output:Total number of characters:05
Number of vowels:01
reversed string=ywons*/
public class Snowy{
public void Method1(String s1)
{
//s1 = "snowy"
//s1=[Link]();
int len=[Link]();
[Link]("No. of characters: "+len);
char result; int vowel=0;
for(int i=0;i<len;i=i+1)
{
result=[Link](i);
if( (result=='A')||(result=='E')||(result=='I')||(result=='O')||(result=='U')
||(result=='a')||(result=='e')||(result=='i')||(result=='o')||(result=='u'))
{
vowel=vowel+1;
}}
[Link]("No. of vowels "+vowel);
for(int j=len-1;j>=0;j=j-1)//4;4>=0
{
char rev=[Link](j);//ywons
[Link](rev);
}}}
/*Question 2:SNOWY PROGRAM
Write a program in java to input any given string and calculate total
characters and vowels present in a given string and reverse it
Sample Input :Snowy
Output:Total number of characters:05
Number of vowels:01
*/
public class Snowy1{
public void Method1(String s1)
{
// String s1=[Link]();
int len=[Link]();
[Link]("No. of characters: "+len);
char result=' '; int vowel=0;
for(int i=0;i<len;i=i+1)
{
result=[Link](i);
switch(result)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vowel=vowel+1;
}}
[Link]("No. of vowels "+vowel);
for(int j=len-1;j>=0;j=j-1)
{
char rev=[Link](j);
[Link](rev);
}}}
Consonents program
public class Consonents
{
public void Consonents1(String name)
{
int i;
name=[Link]();
int len=[Link]();char ch;
for(i=0;i<len;i=i+1)
{
//name=[Link]();
ch=[Link](i);
if((ch=='A') ||(ch=='E')||(ch=='I')||(ch=='O')||(ch=='U') )
continue;
else
[Link](ch);
}}}
public class Consonents
{
public void Consonents1(String name)
{ //String name - "SNOWY";
int i;
name=[Link]();
int len=[Link]();char ch;
String a="";
for(i=0;i<len;i=i+1)
{
//name=[Link]();
ch=[Link](i);
if((ch!='A') &&(ch!='E')&&(ch!='I')&&(ch!='O')&&(ch!='U'))
{
a=a+ch;}}//""+L=L+N+D+N=LNDN
[Link](a+"\t");
}}
DAY 16:-
PROGRAM 16:-
/*Palindrome:
Given string and reverse string are one and the same or if
u read
the string from left to right or vice versa ,it remains
the same
Given String Reverse String
Liril Liril
Arora Arora
Mom Mom
*/
public class Palindrome
{
public void Palin(String name)
{
// String p="liril";
name=[Link]();//LIRIL
int len=[Link]();//05
String rev="";char name1;//
for(int i=len-1;i>=0;i=i-1)//i=5-1=4-1=3
{
name1=[Link](i);//charAt(4)=L,charAt(3)=I
rev=rev+name1;//""+l=L+I=LI+R=LIR+I=LIRI+L=LIRIL
}
if([Link](rev)==0)//LIRIL
//if([Link](rev))//if([Link](rev))
[Link](name+"and "+rev+"are one &the same "+"hence it is
palindrome");
else
[Link](name+" and "+rev+" are not one & the same "+" hence
it is not a palindrome");
}}
DAY 17:-
PROGRAM 17:-
/* Question :Write a program in java to accept a string
* and display the number of
uppercase,lower case,
digit and special character
Sample Input:Kavya_14
Output:
Number of UpperCase:01
Number of lowerCase:04
Number of special character:01
Number of digit-02
*/
public class Program17
{
//Kavya_14
void charCheck(String name)
{
int up=0;
int lc=0;
int dig=0;
int sp=0;int i;
int len=[Link]();//08
for(i=0;i<len;i=i+1)
{
char ch=[Link](i);//
if (ch >= 'A' && ch <= 'Z')
up=up+1;
else if (ch>='a' && ch<='z')
lc=lc+1;//0}+1
else if(ch>='0' && ch<='9')
dig=dig+1;//1+1=2
else
sp=sp+1;//1
}
[Link]("The number of uppercase character is"+up);
[Link]("The number of lowercase character is"+lc);
[Link]("The number of special case character is"+sp);
[Link]("The number of digit is"+dig);
}}
/* Question :Write a program in java to accept a string and display the number of
uppercase,lower case,digit and special character
*Sample Input:Kavya_14
Output:
Number of UpperCase:01
Number of lowerCase:04
Number of special character:01
Number of digit-02
*/
public class Checking
{
void CharCheck(String name)
{
int up=0;
int lc=0;
int dig=0;
int sp=0;int i;
int len=[Link]();
for(i=0;i<len;i=i+1)
{
char ch=[Link](i);
if (ch >= 'A' && ch <= 'Z')
up=up+1;
else if(ch>='a' && ch<='z')
lc=lc+1;
else if(ch>='0' && ch<='9')
dig=dig+1;
else
sp=sp+1;
}
[Link]("The number of uppercase character is"+up);
[Link]("The number of lowercase character is"+lc);
[Link]("The number of special case character is"+sp);
[Link]("The number of digit is"+dig);
}}
DAY 18:-
PROGRAM 18:_
/*Write a program in java to input a string and print the
text with uppercase and lower case reverse but all other
* character remains the same
* Sample Input:"welcome_to _school_2020"
* Sample Output:"WELCOME_TO_SCHOOL_2020"
*/
public class Welcome_to_School
{
//welcome
public void Convert(String p)
{
int l=[Link]();//17
String v="";
for(int i=0;i<l;i=i+1)
{
char ch=[Link](i);//w
if((ch>='A')&&(ch<='Z'))
{
char c=[Link](ch);
v=v+c;
}
else if((ch>='a')&&(ch<='z'))
{
char d=[Link](ch);
v=v+d;//""+W=W+E=WELCOME
}
else
v=v+ch;//WELCOME+_=WELCOME_
}
[Link](v);
}}
DAY 19:-
PROGRAM 19:-
/*Piglatin:
piglatin:Write a program that encodes a word into pig latin .To translate
a word into a Piglatin word,convert the
word into uppercase and then place the first vowel of the original word
as the start of the new word along
with the reamining [Link] alpahbets present before the vowel
being shifted towards the end followed by "AY"
Sample Input:LONDON
Sample OUTPUT:ONDON+L+"AY"=ONDONLAY
2)Sample Input:TROUBLE
Sample Output:OUBLE+TR+"AY"=OUBLETRAY
*/
public class Piglatin
{
public void Piglet1(String name)
{
//sample input=trouble
name = [Link]();
int i;
String c,d;
int len=[Link]();//06
for(i=0;i<len;i=i+1)
{
char chr=[Link](i);//i=0---L,i=1-O
if((chr=='a')||(chr=='e')||(chr=='i')||(chr=='o')||(chr=='u')
||(chr=='A')||(chr=='E')||(chr=='I')||(chr=='O')||(chr=='U'))
break;
}
c=[Link](i,len);//1,6-1,2,3,4,5 -------ondon
d=[Link](0,i);//0,1=0-l
[Link](c+d+"ay");//ondon+l+ay=ondonlay
}}
DAY 20:-
PROGRAM 20:-
/*"January 26 is celebrated as the Republic day of India ".
Write a program to change 26 to 15 .January to August,Republic to Independence
and finally
print "August 15 is celebrated as Independence Day of India" */
public class Independence
{
public void Independence1()
{
String str="January 26 is celebrated as the Republic Day of India";
String str2="August";
String str3="15";
String str4="Independence";
String str5="January";
String str6="26";
String str7="Republic";
String temp1=[Link](str5,str2);//January ,August-----------August 26 is
celebrated as repulic day of india
String temp2=[Link](str6,str3);//26 15//August 15 is celebrated as
Republic Day of India
String temp3=[Link](str7,str4);//Republic Independence//August 15 is
Celebrated as Independence Day of India
[Link](temp3);
}
public void V2()
{
String str="January 26 is celebrated as the Republic Day of India";
String s=[Link]("January 26 is celebrated as the Republic Day of
India","August 15 is celebrated as Independence Day of India");
[Link]("New string is "+s);
}}
DAY 21:-
PROGRAM 21:-
/*Write a program in java to enter a string and print the string in an
alphabetical orde of its alphabets
Sample Input:COMPUTER
Sample OUTPUT:CEMOPRTU
*/
public class Order
{
public void Alphabet1(String str)
{
int ch;
int len=[Link]();//08
for(int i='A';i<='Z';i=i+1)
{
for(int j=0;j<len;j=j+1)
{
ch=[Link](j);
if(ch==i)
[Link]((char)ch);
}
}
}
}
DAY 22:
PROGRAM 22:
/* Write a program in java to accept a given string in lower case and replace 'e'
with '*'
Sample Input="Percentage"
Sameplr Output=P*rc*ntag*
*
*/public class Percentage1
{
public void P1(String n)
{
//n="Percentage"
String s=[Link]();
int len=[Link]();//10
for(int i=0;i<len;i++)
{
char ch=[Link](i);
if(ch=='e')
ch='*';
[Link](ch);
}}
public void P2(String n)
{
//n="Percentage"
String s=[Link]();
String ch=[Link]('e','*');
[Link](ch);
}}
Program 23:
/* Write a program in java to accept a string in lower case
* convert all the first
character in uppercase and display the output
Sample Input:"world is beautiful"
Sample Output:World Is Beautiful
*/
public class World_is_beautiful
{
public void Beautiful(String str)
{
char chr1;
str=" "+str; //
String str1="";
int len=[Link]();//09
for(int i=0;i<len;i=i+1)
{
char chr=[Link](i);//
if(chr==' ')
{
chr1=[Link](i+1);
str1=str1+' '+[Link](chr1);
i=i+1;
}
else
str1=str1+chr;
}
[Link]("new string is "+str1);
}}
DAY 23:
PROGRAM 24:
/*Write a program in java input a double sequence characters in a given string.
and to count the number of double sequence characters present in a given string.
Sample Input"She was feeding the little rabbit with an apple"
Sample Output:04 */
public class Sequence
{
public void Seq(String s)
{// littll rabbit-02-e-20,a-10,su-10
int i, count=0;
String str=[Link]();//
int len=[Link]();//
for(i=0;i<(len-1);i=i+1)//
{
char c=[Link](i);
char ch=[Link](i+1);
if(ch==c)
count=count+1;
}
[Link]("No. of double sequence characters: "+count);
}}
DAY 24:
PROGRAM 25:
/*Write a program in java that ask the user name and then greet the user
* by name and
* before displaying the user name ,it has to convert into upper case
* Example :If the user name is Fred,then the program should respond
* "Hello,FRED,nice to meet you "
*
*/
public class Greet
{
public void Greet1(String name)
{ //name="Fred"
String s1=[Link]();
[Link]("Hello, "+s1+", nice to meet you.");
}
}
DAY 24:
PROGRAM 26:
/* Write a program in java to accept a string in lower case
* convert all the first
character in uppercase and display the output
Sample Input:"world is beautiful"
Sample Output:World Is Beautiful
*/
public class World_is_beautiful
{
public void Beautiful(String str)
{
char chr1;
str=" "+str; //
String str1="";
int len=[Link]();//09
for(int i=0;i<len;i=i+1)
{
char chr=[Link](i);//
if(chr==' ')
{
chr1=[Link](i+1);
str1=str1+' '+[Link](chr1);
i=i+1;
}
else
str1=str1+chr;
}
[Link]("new string is "+str1);
}}
DAY 26:
PROGRAM 27:
/* Write a program to enter a sentence from the keyboard and count the number of
times a particular
word occurs in it. Display the frequency of the search word.
Example:
INPUT:
Enter the sentence: the quick brown fox jumps over the lazy dog.
Enter a word to be searched: the
OUTPUT:
Searched word occurs 2 times.*/
class Frequency{
public void Frequency1(String sent,String word1)
{
//the is the---o/p---2
String word = "";
int count = 0;
for(int i = 0; i < [Link](); i++){
char ch = [Link](i);
if([Link](ch))
word += ch;
else
{
if([Link](word1))
count++;//count=1;
word = "";
}
}
[Link]("Searched word occurs " + count + " times.");
}}
DAY 27:
PROGRAM 27:
NOTHING(JUST H.W.)
DAY 28:
PROGRAM 28:
/*Write a program to input a sentence and print
* the number of characters found in the longest
* word of the given sentence.
For example, if s = “India is my country”
then the output should be 7.
*/
//my country
class Longest{
public void Longest1(String s)
{
s = [Link]() + " ";// s=s+" "
String word = "";//
String longest = "";
for(int i = 0; i < [Link](); i++)//11
{
char ch = [Link](i);//m
if(ch == ' ')
{
if([Link]() < [Link]())
longest = word;
//word = "";
}
else
word += ch;//word=word+ch=""+c=country
}
int len = [Link]();
[Link]("Length = " + len);
}
}
DAY 29:
PROGRAM 29:
/*Write a program to input a string in uppercase and print
the frequency of each character.
Example:
INPUT: COMPUTER HARDWARE
OUTPUT:
Characters Frequency
A 2
C 1
D 1
E 2
H 1
M 1
O 1
P 1
R 3
T 1
U 1
W 1
*/
class Frequency{
public void Freq1(String s)
{
//RABBIT-A-1,B-2,I-1,R-1,T-1
[Link]("String: ");
s = [Link]();
for(char ch = 'A'; ch <= 'Z'; ch++){
int count = 0;
for(int i = 0; i < [Link](); i++){
char x = [Link](i);
if(x == ch)
count++;
}
if(count > 0)
[Link](ch + "\t" + count);
}
}}
DAY 30:
PROGRAM 30:
/*Write a program to accept a word and convert it
* into lowercase if it is in uppercase,
and display the new word by replacing only the vowels
with the character following it.
Example:
Sample Input: computer
Sample Output: cpmpvtfr
*/
class Word{
public void Word1(String w)
{
[Link]("Word = ");
w = [Link]();
//int index = [Link](' ');
/*if(index > 0)
w = [Link](0, index);*/
w = [Link]();
String t = "";
for(int i = 0; i < [Link](); i++)
{
char ch = [Link](i);
/*switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':*/
if((ch=='a') ||(ch=='e') ||(ch=='i') ||(ch=='o') ||(ch=='u') )
t += (char)(ch +
1);//t=t+(ch+1)=c+p=cpmp+u=cpmp+v=cpmpv+f=cpmvt+f=cpmpvtf
// break;
//default:
else
t += ch;// t=""+c=cp+m=cpm+p=cpmpv+t=cpmpvt
}
[Link](t);
}}
PROGRAM 31:
/*Write a program to accept a word and convert it into lowercase if it is in
uppercase,
and display the new word by replacing only the vowels with the character
following it.
Example:
Sample Input: computer
Sample Output: cpmpvtfr
*/
class Word1{
public void Word1(String w)
{
w = [Link]();
w = [Link]();
String t = "";
for(int i = 0; i < [Link](); i++){
char ch = [Link](i);
if((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u'))
t += (char)(ch + 1);
else
t += ch;
}
[Link](t);
}
}
DAY 31:
PROGRAM 31:
/*Write a program to assign a full path and file name as
* given below. Using library functions,
* extract and output the file path, file name and
* file extension separately as shown.
INPUT: C:/Users/admin/Pictures/[Link]
OUTPUT:
Path: C:/Users/admin/Pictures/
File name: flower
Extension: jpg
*/
class Path{
public void Path1(String fp)
{
//fp = "C:/Users/admin/Pictures/[Link]";
int last = [Link]('/');
int dot = [Link]('.');//30
//int last=[Link]('/');//23
String p = [Link](0, last + 1);//0 to 24 ,it takes only 0 to 23---------------
String f = [Link](last + 1, dot);//24 to 30,it prints 24 to 29-----flower
String ext = [Link](dot + 1);// 31to 34 ,31to 33------jpg
[Link]("Path: " + p);
[Link]("File name: " + f);
[Link]("Extension: " + ext);
}}
//first line it is twenty three
PROGRAM 32:
/*Write a program to assign a full path and file name as given below. Using library
functions, extract and output the file path, file name and file extension separately
as shown.
INPUT: C:\Users\admin\Pictures\[Link]
OUTPUT:
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
*/
class Path1{
public void Path1(String fp)
{
fp = "C:\Users\admin\Pictures\[Link]";
int last = [Link]('\');
int dot = [Link]('.');//30
String p = [Link](0, last + 1);//0 to 24 ,it takes only 0 to 23---------------
String f = [Link](last + 1, dot);//24 to 30,it prints 24 to 29-----flower
String ext = [Link](dot + 1);// 31to 34 ,31to 33------jpg
[Link]("Path: " + p);
[Link]("File name: " + f);
[Link]("Extension: " + ext);
}}
DAY 32:
PROGRAM 33:
public class Test{
public void joyString(String s, char ch1, char ch2){
//s="TECHNALAGY"
//ch1='A'
//ch2='O'
s=[Link](ch1,ch2);
[Link](s);
}
public void joyString(String s)
{
int i1=[Link](" ");
int i2=[Link](" ");
[Link](i1);
[Link](i2);
}
public void joyString(String s1, String s2)
{
String s3=[Link](s2);
[Link](s3);
}
}
PROGRAM 34:
/Design a class to overload a function joyString() as follows:
(i) void joyString(String s, char ch1, char ch2) with one string argument and two
character
arguments that
replaces the character argument ch1 with the character argument ch2 in the given
string s and prints
the new string.
Example:
INPUT:
s = “TECHNALAGY”
ch1 = ‘A’
ch2 = ‘O’
OUTPUT:
“TECHNOLOGY”
(ii) void joyString(String s) with one string argument that prints the position of the
first space and the last space of the given string s.
Example:
INPUT:
s = “Cloud computing means Internet-based computing”
OUTPUT:
First index: 5
Last index: 36
(iii) void joyString(String s1, String s2) with two string arguments that combines
the
two strings with a space between them and prints the resultant string.
Example:
INPUT:
s1 = “COMMON WEALTH”
s2 = “GAMES”
OUTPUT:
COMMON WEALTH GAMES
(use library functions) */
class Overload{
public void JoyString(String s, char ch1, char ch2){
s = [Link](ch1, ch2);//TECHNALAGY ,ch1='A' ch2='O'
[Link](s);//o/p TECHNOLOGY
}
public void JoyString(String s){
int first = [Link](' ');//"Cloud computing means Internet based computing"
int last = [Link](' ');
[Link]("First index: " + first);//5
[Link]("Last index: " + last);//36
}
public void JoyString(String s1, String s2){
/*String s=s1+" "+s2;
[Link](s);*/
String s=[Link](" ");
String s3=[Link](s2);
[Link](s3);
}}
PROGRAM 34:
public class concat1
{
public void joyString(String s1, String s2)
{
String res = " ";
res = [Link](" ");
res= [Link](s2);
[Link](res);
}}
PROGRAM 35:
public class Space{
public void joyString(String s){
int res1 = [Link](' ');
int res2 = [Link](' ');
[Link]("First Index: " + res1);
[Link]("Last Index: " + res2);
}}
PROGRAM 36:
public class Test1
{
public void joyString(String s,char ch1,char ch2)
{
String res ;
res = [Link](ch1,ch2);
[Link](res);
} }
DAY 33:
PROGRAM 37:
/*Design a class to overload a function check() as follows:
void check(String str, char ch) – to find and print the frequency of a
character in a string.
Example:
INPUT:
str =“success”
ch = ‘s’
OUTPUT:
Number of s present is = 3.
void check(String s1) – to display only vowels from s1, after converting
it to lowercase.
Example:
INPUT:
s1 = “computer”
OUTPUT:
oue
*/
class Overload{
public void check(String str, char ch){
int count = 0;//str="success" ch='s'
for(int i = 0; i < [Link](); i++){
if(ch == [Link](i))
count++;//count=1+1=2+1=3
}
[Link]("Frequency = " + count);//03
}
public void check(String s1){
s1 = [Link]();//computer--------oue
for(int i = 0; i < [Link](); i++){
char ch = [Link](i);
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
[Link](ch + "\t");
} } }}
PROGRAM 38:
/*Design a class to overload a function joyString() as follows:
(i) void joyString(String s, char ch1, char ch2) with one string
argument and two character arguments that
replaces the character argument ch1 with the character argument
ch2 in the given string s and prints the new string.
Example:
INPUT:
s = “TECHNALAGY”
ch1 = ‘A’
ch2 = ‘O’
OUTPUT:
“TECHNOLOGY”
(ii) void joyString(String s) with one string argument that prints
the position of the
first space and the last space of the given string s.
Example:
INPUT:
s = “Cloud computing means Internet-based computing”
OUTPUT:
First index: 5
Last index: 36
(iii) void joyString(String s1, String s2) with two string arguments
that combines the
two strings with a space between them and prints the resultant
string.
Example:
INPUT:
s1 = “COMMON WEALTH”
s2 = “GAMES”
OUTPUT:
COMMON WEALTH GAMES
(use library functions) */
DAY 34: PROGRAM:
/*Write a menu-driven program to display the pattern
* as per user’s choice:
Pattern 1 Pattern 2
ABCDE B
ABCD LL
ABC UUU
AB EEEE
A
For an incorrect option, an appropriate error message
should be displayed.
*/
import [Link].*;
class Menu{
public void main()
throws IOException{
InputStreamReader in = new InputStreamReader([Link]);
BufferedReader br = new BufferedReader(in);
[Link]("1. Pattern 1");
[Link]("2. Pattern 2");
[Link]("Enter your choice: ");
int choice = [Link]([Link]());
switch(choice){
case 1:
String s = "ABCDE";//ABC
for(int i = [Link](); i > 0; i--)
[Link]([Link](0,i));
break;
case 2:
s = "BLUE";
for(int i = 0; i < [Link](); i++){
char ch = [Link](i);
for(int j = 0; j <= i; j++)
[Link](ch);
[Link]();
}
break;
default:
[Link]("Invalid choice!");
} }}
PROGRAM
public class Test
{public void T()
{String n="LUCKNOW";
n=[Link](0,1);
[Link](n);}}
DAY 35:-
PROGRAM :_
/* Question
Write a program to input a sentence and convert it into
uppercase and count and display the total number
of words starting with the letter ‘A’.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION
TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter
‘A’ = 4. */
//AND AND.
import [Link].*;
class Letters{
public void Letetrs1(String s)
{
[Link]("Enter the sentence: ");
s = [Link]();//AND AND.=08
int count = 0;
String word = "";
for(int i = 0; i < [Link](); i++){
char ch = [Link](i);//n
switch(ch){
case ' ':
case '.':
case '?':
case '!':
if([Link](0) == 'A')//[Link](0)------A==A
count++;//count=01+1=02
word = "";
break;
default:
word += ch;//=""+A=A+n=An+d=And
}}
[Link]("Total number of words starting with letter 'A' = " +
count);
}}
DAY 36:-
PROGRAM
/*Write a program to accept a name containing three words along with sir names
Sample Input:Mohandas Karamchand Gandhi
Sample output:M.K. Gandhi
*/
class InitialsWidName
{
static void teja(String st)
{
int l = [Link]();
String bin="";
[Link]([Link](0));
for(int i=0;i<l;i++)
{
char ch=[Link](i);
if([Link](ch))
[Link]("."+[Link](i+1));
}
int s =[Link](' ');
[Link]([Link](s+2,l));
}
}
DAY 37:-
/*Read a line and print the letters :this program reads
line of text entered by the user .It prints list of letters that
occur in the text and reports how many letters are found
Sample Input: ABBA
Sample Output: 04
*/
public class Howmany {
public void Sequence(String str)
{
//String str="AB7898"
int count = 0;
[Link]("String: "+str);//ABBA
for (int i = 0; i < [Link](); i++) {
if ([Link]([Link](i)))
count++;//count=1+1=3+1=4
}
[Link]("Letters: "+count);
}}
DAY 38:-
/*Read a line and print the letters .This program reads a line of text
entered by the user .It prints list of letters that occur in the text and report
how many different letters are found
Sample Input:ABBA
Sample output:A-02
B-02
*/
public class Different
{
public void Letters(String str)
{
int i;
int count;
int letter;
str=[Link]();//ABBA
count=0;
int len=[Link]();
for(letter='A';letter<='Z';letter=letter+1)
{
for(i=0;i<len;i=i+1)
{
char c=[Link](i);//A
if(letter==c)//A==A,A==B,A==B,A==A,A==B,B==B
{
[Link]((char)(c));
[Link]();
count=count+1;//1
break;
}
}}
[Link]("There were"+count+"different letters");
}}
Day 39(a)
/*Write a program to accept the string as "computer is fun" enter in lowercase
Sample output:retupmoc si nuf
*/
public class Reverse
{
public void Reverse1(String s)
{
int i;
String t="";
s=s+" ";
int len=[Link]();//16
for(i=0;i<len;i=i+1)
{
char c=[Link](i);
if(c!=' ')
t=t+c;
else
{
StringBuffer a=new StringBuffer(t);
StringBuffer y=[Link]();
[Link](y+" "); //retupmoc si
t="";
}}}}
Day 39(b)
/*
Write a program to accept a sentence. Display the sentence in reversing order of its
word.
Sample Input: Computer is Fun
Sample Output: Fun is Computer*/
public class ReverseWords
{
public void Reverse(String str)// IS FUN
{
[Link]("Enter a sentence:");
str = " " + str;
String word = "";///output:
int len = [Link]();
for (int i = len - 1; i >= 0; i--) {
char ch = [Link](i);//n
if (ch == ' ') {
[Link](word + " ");//fun
word = "";
}
else {
word = ch+word;//n+""=fun
} } }}
Day 40(a)
/*To calculate number of spaces, words, vowels and consonants from a string:-
*/
class VowelCons
{
public void Vowels1(String str)
{//su-10,e-20
[Link]("Give a string"); //London Bridge
int len=[Link]();//13
int count=0;
int vow=0;
for(int i=0;i<len;i++)
{
char ch=[Link](i);
if(ch==' ')
count++;//01
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='
U')
vow++;//01+1=2+1=3+1=4
}
[Link]("[Link] spaces= "+count);//0/[Link]("[Link] words=
"+(count+1));//02
[Link]("[Link] vowels= "+vow);//04
int j=len-count-vow;//13-1-4=08
[Link]("[Link] consonants= "+j);
}}
/* Output:-
Give a string
What is your name?
[Link] spaces= 3
[Link] words= 4
[Link] vowels= 6
[Link] consonants= 9*/
Day 40(b)
/*To calculate number of spaces, words, vowels and consonants from a string:-
*/
class VowelCons
{
public void Vowels1(String str)
{//su-10,e-20
[Link]("Give a string"); //London Bridge
int len=[Link]();//13
int count=0;
int vow=0;
for(int i=0;i<len;i++)
{
char ch=[Link](i);
if(ch==' ')
count++;//01
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='
U')
vow++;//01+1=2+1=3+1=4
}
[Link]("[Link] spaces= "+count);//0/[Link]("[Link] words=
"+(count+1));//02
[Link]("[Link] vowels= "+vow);//04
int j=len-count-vow;//13-1-4=08
[Link]("[Link] consonants= "+j);
}
}
/* Output:-
Give a string
What is your name?
[Link] spaces= 3
[Link] words= 4
[Link] vowels= 6
[Link] consonants= 9*/