0% found this document useful (0 votes)
5 views11 pages

Thurs Batch Class X 8th May Progs

The document contains a series of Java programs that perform various string manipulations, including reversing words, replacing substrings, sorting characters, and encoding/decoding letters. Each program is structured to accept user input and process it according to the specified functionality. The document includes code snippets and comments that outline the intended operations and expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Thurs Batch Class X 8th May Progs

The document contains a series of Java programs that perform various string manipulations, including reversing words, replacing substrings, sorting characters, and encoding/decoding letters. Each program is structured to accept user input and process it according to the specified functionality. The document includes code snippets and comments that outline the intended operations and expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Date

Paqe

Dau- 9
S482 WAP to accept a sentence and disploy in the follonina fonma
WoHd no. Wond Revense VOHe Conaonant
1 We ek
2.
3 33
eiou
Sting s=se.nextine(); Stxing g"AETOU"+=,m=";$=9+b"
jnt v:0, c=0, ctn=0:;Sustem.qut. printn C"'NoHdnolt VoweL\Eonsonan;
Nond)tRevense
fonCint i0; i[s.length );i**)
chat ch=s.chanAeC);
4Cchl)i
tettch: m= cht m;
laindea0f(ch)! -1)v*; else eir,f
elgei
Cty tt:
System.out. pxintln (ch':teil"'*m"y*t"t:
tm=

*9497WAP to edlace aNOHd by anothen NoHd nhene seanch od con be


paunt af anothernoHd. Ihis is hisBoHy, is>Wa8
Stxing s-9e.nextdine); Thwas was hwastoy
Sustem.out.pintn("Seomch wond " Sting : Se.nextO;
Sisterm.out. pxintln Replace od"), StündÑ u= se.nextHO, inte0;
nhile Ctnue'lint pos= .indeaOf(,0),
fl pos== -1) bHeak, a.length(0).
S9.Subsing (O, pos)t
pxiotn(e)S. Suosthung (pos
System.oui
C= pöst ylength0,i
Sustem.out pxintlnls);
Page

050) WAP to acept a sentence and awrange each oHd af the


Sentence in chanache1-Nise manne. We ate didian
Sbing s<se.neatdine(); Stxing t-",m=";keoen Jaidnn
fon Gnt i-0;iss.length);it+)
Chan ch=S. Chantt);
Cch)
tet tch, nhinn
else
Chan aC] t.tochontcuy 0;
ll chan AxCLy Soting
fonCnlength-1,;
ox (jnt jt+)
j-0;(a.length-l,;jt)
0; kialengh-1;ktt)
Cin)aCk)>(nate11)L
alk] alk1],
Otun s01fed osd=newStind
m=mt H o ,

Sustem.out pxintln(s);
51) CoHCuhOM encoding ABeD-+4 EFGH
otHing &se. nexe(); XYZt5*CDE.
Sustem.out.pxintn C" Enten a no");int n=se.nettnt ),
nEn 26 Stxing t-n,
fon Cint i =0, iK3length);i )
chonchS.chauAYCi);:
CchA 2chts}
ch: Cchonchn),
1Cch ch Cchan)ch- 26):3
else i Cch >a ee chz)
ch Cchan) Cchn),
Paqe

(che'z?) ch: (chan(ch- 96),3


et; System.out. pxintn (s)
52Cuculan decoding ABC- -4WYE
Sting S- SC.negtaine 0;
System.out. printin "Enten ano." int n=se.neatdnH).
Fon Cint i=o; iKs.lengtn0,it+)
chan ch=S.chanAtCO;
ch= Ccha)Cch-n)
tCchanc'A) h= (chan)(ch+ 26);1
dh= Cchan)ch-n)
tlchan'a) heCchan)lh+26),1
tttch;
st, Syskem. out pxint1n (s),
S53) NAPa to Qccept a sentence and mesense he sent encein nOHd
se mannei. We one fndian
StHing s se.nextdine), Stsing ",mndian one We
fon Cint i=0, iKs.length);it:)i
chan ches.chanAt (i);
ztt chi
elsei
tHim (0;Sustem.out.pkintn (9);
Date
Page

6542 WAP to accept asentencefxom Hhe usen and aO10ngehe


sentence in noxd- oise mannen (dichonau-o8e soxting)
Stxing 3:Se.nextdine);S=S.txim ); mm oo aa dd kk
8=S+"6; int a-0,m=0; Shingta dd kk mm 0o
fom Cint i-0, i<s.length(0;i)2 lnond count
Stnind a[l:new Stsüng [x1;
oxCint ie0;iKs.lengthO; i
Chon ch= s.chatAH(iD,
lch'=6)
tett ch;
elsei
am+]=t; -", ii Shing wonds into Sbing, amay
onint j-O;isa.lengjt-L:it)|lAxiauysornting
fonlint 0: alength
ifCát;i.ompane lo
chan k=ctjl;
al1: alj+1];
ali:1]: k,
Hon Cint iro; iaa. length;i ) new sertence
bn=n+"b"* aliJ;
SEntxim, System.0ut.pxintn(an,
import java.util.*; Enter Sentence:
class String48{ We are Indian
public static void main() { Word no. Word Reverse Vowel Consonant
Scanner sc=new Scanner (System.in): 1 We eW 1 1

System.out .println( "Enter Sentence:"): 2 are era 2


String s= sc.nextLine(); s=s+" "; String x="AEIOUaeiou" , t="", m=""; 3 Indian naidnI 3 3
int v=0, c=0, ctr=0;
System.out.println( "Word no.\tWord\tReverse\ tVowel\ tConsonant");
for(int i-0;i<s.length();it+){
char ch=s .charAt(i);
if (ch!=' "X
t=t+ch; m= ch+m;
if (x. indexOf (ch)!= -1) v++; else c++;)
else{
ctr++;
System.out.println(ctr+"\t\t"+t+"\t"+m+"\t"+v+"\t"+c);
t=m="" ;v=c=0 ;
import java.util.*; Enter Sentence:
class String49{ This is history
public static void main(){ Enter Search Word:
Scanner sc=new Scanner(System.in); is
System. out .println( "Enter Sentence:"): Enter Replace Word:
String S= SC.nextLine( ): was
System. out .println( "Enter Search Word:"); Thwas was hwastory
String X= sc.next();
System.out.printin("Enter Replace Word:");
String y= sc.next(); int c=8;
while(true){ int pos= s.indexof(x, c);
if (pos == -1) break;
S= S.substring(0, pos) +y+s.substtring(pos+x.length());
C=posty. length (0:}
System. out .println(s); }}
import java.util.*; Enter Sentence:
class String50{ We are Indian
public static void main(String args[]){ We aer Iadinn
Scanner sc=new Scanner (System.in);
System.out .println( "Enter Sentence:");
String S= sC.nextLine(0: s=s+" "; String t=" " , m="";
for (int i-0;i<s.length(0;it+){
char ch=S.charAt (1);
if (ch!=' )
t=ttch;
else{
char a]=t.toCharArray();
for(int j=0;j<a.length-1;j++)
for (int k=0;k<a.length-j-1;k++)
if(int)(a[k])> (int)(a[k+1 ] )){
char c= a[k]:
a[k]= a[k+1):
a[k+1]=c;}
String sortedword= new String(a) :
m=m+" "+sortedword; t="";}}
s=m.trim(); System.out.println(s);
import java.util . *; Enter String:
class String51{ ABCD
public static void main(){ Enter a number to add:
Scanner sc=new Scanner (System.in); 4
System. out .println("Enter String:"); EFGH
String $= sC.nextLine(): Enter String:
System.out.println("Enter a number to add:"); Xyz
int n=sc.nextInt (); n=n%26; String t=""; Enter a number to add:
for(int i-0;i<s. length() ;it+){ 5
char ch=s.charAt (i); cde
if (ch>='A' && che='Z'){
ch=(char) (ch+n) ;
if(ch>'Z' )ch=(char)(ch-26) :}
else if(ch>='a' && che='z'{
ch=(char) (ch+n) :
if(ch>'z' )ch=(char) (ch-26);}
t=ttch;:

S=t; System . out.println (s);


import java.util.*; Enter String:
class String52{ ABCDE
public static void main(){ Enter a number to subtract:
Scanner sc=new Scanner(System.in); 4
System. out .println( "Enter String:"); WXYZA
String s= sc.nextLine();
System.out.println("Enter a number to subtract :");
int n=sc.nextInt 0: n=n%26; String t="";
for (int i=0;i<s.length() ;i++){
char ch=s.charAt(i);
if (ch>='A' && ch<='Z'){
ch=(char) (ch-n) ;
if (che'A' )ch=(char) (ch+26 ) :}
else if (ch>='a' && ch<='z'){
ch=(char) (ch-n);:
if (che'A')ch=(char) (ch+26):)
t=t+ch;

s=t; System .out.println(s) ;


import java.util.*; Enter Sentence:
class String53{ We are Indian
public static void main(){ Indian are We
Scanner sc=new Scanner (System.in);
System.out.println("Enter Sentence:");
String s= sc.nextLine ();
String t="", m=""; s=s+" ";
for (int i-0;i<s.length() ;it+) {
char ch=s.charAt (i);
if (ch!=" ')
t=ttch;
else{
m=t+" "+m; t="":)}
S=M.trim(); System. out.println(s);
class String54{ Enter Sentence:
public static void main(){ mm oo aa dd kk
Scanner sc=new Scanner (System.in) ; aa dd kk mm o0
System.out.println("Enter Sentence:");
String s= sc.nextLine(); s=s.trim();
String t="",n=""; s=s+" "; int x=0, m=0;
for (int i-0;i<s.length() ;it+) {
if (s. charAt (i)== ' ) x++;}
String a[]=new String[x]:
for (int i=0;i<s.length () ;it+) {
char ch=s.charAt(i) ;
if (ch!=' ')
t=ttch;
else{
a[m++]=t;t="" :}}
for (int i-0; i<a.length-1;it)
for(int j=0:j<a.length-i-1;j++)
if (a[j].compareTo (a[j+1] ) >8){
String k=a[j]:
alj]=a[j+1 ];
alj+1]=k;}
for (int i-0;i<a.length ;i++)
n=n+" "+a[i]:
n=n.trim(); System.out.println (n) :}}

You might also like