Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views15 pages

Java Program for Mixing Words

Uploaded by

adoringhopper0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

Java Program for Mixing Words

Uploaded by

adoringhopper0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

import java.io.

*;
class Mix{
String wrd;
int len;
public Mix(){
wrd = "";
len = 0;
}
public void feedWord()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
wrd = br.readLine();
wrd = wrd.trim();
wrd = wrd.toUpperCase();
if(wrd.indexOf(' ') > 0)
wrd = wrd.substring(0, wrd.indexOf(' '));
len = wrd.length();
}
public void mixWord(Mix p, Mix q){
int i = 0;
int j = 0;
while(true){
if(i < p.len && j < q.len){
this.wrd += p.wrd.charAt(i);
this.wrd += q.wrd.charAt(j);
}
else
break;
i++;
j++;
}
if(i < p.len)
this.wrd += p.wrd.substring(i);
if(j < q.len)
this.wrd += q.wrd.substring(i);
}
public void display(){
System.out.println(wrd);
}
public static void main(String args[])throws IOException{
Mix obj1 = new Mix();
Mix obj2 = new Mix();
Mix result = new Mix();
System.out.print("First word: ");
obj1.feedWord();
System.out.print("Second word: ");
obj2.feedWord();
result.mixWord(obj1, obj2);
System.out.print("Required word: ");
result.display();
}

You might also like